# Setting Up a Chain

note

It is possible to run a "committee" of a single Wasp node, and this is okay for testing purposes.

However, in normal operation, multiple Wasp nodes should be used.

## Trust Setup​

After starting all the wasp nodes, you should make them trust each other. Node operators should do this manually. It's their responsibility to accept trusted nodes only.

The operator can read their node's public key and PeeringURL by running wasp-cli peering info:

wasp-cli peering info

Example response:

PubKey: 8oQ9xHWvfnShRxB22avvjbMyAumZ7EXKujuthqrzapNMPeeringURL:  127.0.0.1:4000

PubKey and PeeringURL should be provided to other node operators. They can use this info to trust your node and accept communications with it. That's done by invoking wasp-cli peering trust <Name for the peer> <PubKey> <PeeringURL>, e.g.:

wasp-cli peering trust another-node 8oQ9xHWvfnShRxB22avvjbMyAumZ7EXKujuthqrzapNM 127.0.0.1:4000

The list of trusted peers of your wasp node can be viewed with:

wasp-cli peering list-trusted

All the nodes in a committee must trust each other to run the chain.

## Starting The Chain​

### Requesting Test Funds (only for testnet)​

wasp-cli request-funds

### Deploy the IOTA Smart Contracts Chain​

You can deploy your IOTA Smart Contracts chain by running:

wasp-cli chain deploy --peers=foo,bar,baz --chain=mychain --description="My chain"

The names in --peers=foo,bar,baz correspond to the names of the trusted peers of the node.

The --chain=mychain flag sets up an alias for the chain. From now on all chain commands will be targeted to this chain.

The --quorum flag indicates the minimum amount of nodes required to form a consensus. The recommended formula to obtain this number floor(N*2/3)+1 where N is the number of nodes in your committee.

After deployment, the chain must be activated by the node operators of all peers.

wasp-cli chain add <name> <chainID> # adds the chain to the wasp-cli config, can be skipped on the wasp-cli that initiated the deployment wasp-cli chain activate --chain=<name>

## Testing If It Works​

You can check that the chain was properly deployed in the Wasp node dashboard (<URL>/wasp/dashboard when using node-docker-setup). Note that the chain was deployed with some core contracts.

You should also have an EVM-JSONRPC server opened on:

<wasp API URL>/chain/<CHAINID>/evm

### Deploying a Wasm Contract​

danger

The WASM VM is experimental. However, similar commands can be used to interact with the core contracts

Now you can deploy a Wasm contract to the chain:

wasp-cli chain deploy-contract wasmtime inccounter "inccounter SC" tools/cluster/tests/wasm/inccounter_bg.wasm

The inccounter_bg.wasm file is a precompiled Wasm contract included in the Wasp repo as an example.

If you check the dashboard again, you should see that the inccounter contract is listed in the chain.

### Interacting With a Smart Contract​

You can interact with a contract by calling its exposed functions and views.

For instance, the inccounter contract exposes the increment function, which simply increments a counter stored in the state. It also has the getCounter view that returns the current value of the counter.

You can call the getCounter view by running:

wasp-cli chain call-view inccounter getCounter | wasp-cli decode string counter int

Example response:

counter: 0
note

The part after | is necessary because the return value is encoded, and you need to know the schema in order to decode it. The schema definition is in its early stages and will likely change in the future.

You can now call the increment function by running:

wasp-cli chain post-request inccounter increment

After the request has been processed by the committee, you should get a new counter value after calling getCounter:

wasp-cli chain call-view inccounter getCounter | wasp-cli decode string counter int

Example response:

counter: 1

### Troubleshooting​

Common issues can be caused by using an incompatible version of wasp / wasp-cli. You can verify that wasp-cli and wasp nodes are on the same version by running:

wasp-cli check-versions