Skip to main content

Getting Started

DEVNET

All contracts by default are interacting with the Coinweb DEVNET (you can find its explorer here). It is a public test network and no registration is needed. You may or may not experience some delays or outages.

The following is the simplest way to create a new Coinweb dApp project. It will create the Hello World example in the directory called my-dapp inside your current folder. The created workspace includes a yarn monorepo with a contract module and a simple UI with the most basic interaction possibilities.

The public repository for the Hello World example can be found here.

Prerequisites

Before starting, please make sure you have the following installed:

  1. Node.js, version ^20.12.0 || ^21.7.0 || >=22.0.0
  2. Corepack, installed globally npm install -g corepack
info

Coinweb modules and repositories rely on corepack which is a zero-runtime-dependency package acting as bridge between Node projects and their package managers. If you have not enabled it, you need to enable it by running:

corepack enable

Additionally Yarn Berry is used as the package manager. It is not needed nor possible to install it globally. It will be preset per project.

Create Your First dApp

create coinweb-dapp is an officially supported way to create Coinweb dApps. It offers a modern build setup with no configuration.

npm.coinweb.io is the official Coinweb public npm registry.

npm create coinweb-dapp@latest
Loading asciinema cast...

This will setup a default Hello World dApp in the my-dapp directory and install all dependencies utilising Yarn Berry which is preset within the project. You can check the folder structure explanation here to have a better overview over the files and folders.

info

Inside the contract module's package the src/onchain folder contains the smart contract logic and the src/offchain folder contains the offchain logic which is used to interact with the smart contract applications front end or back end. Read more about working with contract modules here.

Build the Modules

cd my-dapp
yarn build
Loading asciinema cast...

The project's root build script is used to build the contract module and the UI subsequently. This is important when one module is another one's dependency and therefore the dist folder has to exist before the other module can be built. In this example all contract modules are built first. You can find the build script in the package.json file:

Publish the Contract Module to Coinweb

After your project was built successfully, you can deploy the contract module to Coinweb.

yarn deploy-contracts
Loading asciinema cast...

The smart contract is published to Coinweb by the root yarn deploy-contracts script. After publishing a smart contract to Coinweb it can be invoked/called by anyone. The transaction id that deploys the smart contract is printed by the script and can be tracked at the DEVNET explorer.

Call the Deployed Contract

To execute the root-level script that calls the deployed smart contract, run:

yarn call-contracts

Calling the smart contract executes the logic in the smart contract. This logic writes a claim containing the words "hello world". The transaction id that invokes the smart contract is printed by the script and can be tracked at the DEVNET explorer

Loading asciinema cast...

Finally we can check that the "hello world" claim was actually written by executing a program in the dapp-ui folder.

yarn workspace dapp-ui dev
Loading asciinema cast...

It will show the UI for hello world. You can superficially interact with the contract by changing the parameters and validating them by clicking the button. All the UI component does is fetching the deployed claim from Coinweb by utilising the @coinweb/wallet-lib and displaying it in a form


Keep on reading to familiarize youself with more complex examples and the underlying concepts. The possibilities using Coinweb are endless.

Next Steps


Coinweb © 2024