Skip to main content

Executing Scripts

There is a set of scripts that are preset in the workspace's package.json to interact with the Hello-World repository. Each script will be described in the following sections. It partially introduces the underlying @coinweb/cweb-tool works.

Build the packages

The build command as the name implies builds the modules from the underlying source code of each package.

yarn build
yarn build:cm && yarn build:non-cm && yarn create-index

Build contract modules

Executed from the root directory of the workspace it builds all underlying modules that are marked as .cm first. In this case the build order is important as the underlying dApp imports from the module and therefore it has to exist during build time.

yarn build:cm
yarn workspaces foreach -Ap --include 'packages/*.cm' run build
note

With the foreach loop the top level build commands go through each package and call the package's build script.

Build non contract modules

As the Hello World example does not allow parallel builds of non-cm modules they are build separately by including/excluding the right packages.

yarn build:non-cm
yarn workspaces foreach -Ap --include 'packages/*' --exclude 'packages/*.cm' run build

Create module index

After all packages have been built successfully the first utilisation of the @coinweb/cweb-tool comes handy, that is creating an index of the freshly build contract module. The index is a major part of security when working with contract modules and specifically trusting templates. Instead of using names and human readable aliases an index is a hash composed utilising cweb-config's configuration files.

yarn create-index
cweb-tool create-index .cweb-config/dapp-ecosystem.yaml .dapp-ecosystem-lock.yaml

Deploy the contracts

Deploying a contract means it is going to be pushed to the Coinweb mainnet and therefore published. From there on the contract will be live on Coinweb and can be claimed. The deploy-contracts in the Hello-World example calls cweb-tool's publish action.

yarn deploy-contracts
yarn publish-actions

Cweb-tool's publish gathers, filters and executes actions in one command. It thereby receives the parameters as shown below: dapp-ecosystem.yml, the mnemonic seed phrase, the network to run on and the wallet-lib's graphql endpoint. In Hello-World we use the DEVNET parameters.

yarn publish-actions
cweb-tool publish .cweb-config/dapp-ecosystem.yaml

Call the contracts

When the contract was pushed to Coinweb it is considered live and can be called/invoked from and by anyone. Calling the contract executes the logic of the deployed smart contract. The call-contracts script prepares and invokes all underlying contract modules of the workspace.

yarn call-contracts
yarn call-contracts:prepare && yarn call-contracts:invoke

During the prepare state each contract module in its workspace creates a deploy/.calls-package.yaml file from a template. Which in the end will be used by the create-calls.mjs script to aggregate all contract module calls.

yarn call-contracts:prepare
yarn workspaces foreach --all run prepare-for-package && yarn node ./.cweb-config/create-calls.mjs

Finally when all contract modules calls are aggregated cweb-tool's call command is executed, which given the parameters as displayed below, calls the previously deployed contracts on Coinweb. The parameters are: The aggregated calls.yml file, the mnemonic seed phrase, network to run on and the wallet-lib's graphql endpoint.

yarn call-contracts:invoke
cweb-tool call .cweb-config/calls.yaml
note

In the Hello-World example the call-contracts script calls only one contract although executed from the workspaces root directory. In a scenario, in which multiple contracts are involved, you maybe want to call only one contract or provide a conditional sequence. Everything is possible but must be adapted to the requirements of each dApplication accordingly.

Clean up

Simple helper scripts in order to clean up the contract modules, usually by deleting the files and folders created during the build, deploy, call processes.

yarn clean
yarn clean:me && yarn workspaces foreach --all --p run clean

Clean:me cleans the top level configuration files for a fresh start.

yarn clean:me
rm -rf .dapp-ecosystem-lock.yaml .unfiltered-actions.yaml .actions.yaml

Utils

The way to run tests for all underlying packages is to implement a test script on each package level and then run it from the workspace root.

yarn test
yarn workspaces foreach -Ap run test

Coinweb © 2024