Build & Deploy & Initialize

Congratulations on implementing your smart contract! In this section, you will learn how to build, deploy, and create an instance of it.

Step 1: Build the Smart Contract

Before deploying, you need to compile the smart contract into WebAssembly (wasm) format. Run the following command:

cargo concordium build --out dist/module.wasm.v1 --schema-out dist/schema.bin

This command will compile the contract, store the schema, and compile wasm files in a new folder named "dist" as shown below:

Step 2: Deploy Smart Contract

Deploy the wasm compiled smart contract to the testnet by running the following command:

concordium-client module deploy dist/module.wasm.v1 --sender <YOUR-ADDRESS> --name CIS2-Fractionalizer --grpc-port 20000 --grpc-ip node.testnet.concordium.com

This command connects to the testnet node and deploys the contract:

Note the following:

  • From now on, you don’t have to run your own testnet node for deploying contracts.

  • Essentially, using a public URL (node.testnet.concordium.com), you can connect to a testnet node and will be able to deploy/query nodes.

  • For all operations in this tutorial, you will use the public gRPC endpoint that Concordium provides.

For some use cases you might need to run your own local node as there could be some limitations of this one. If you need more info either check this link or use the support channel.

Step 4: Initialize Smart Contract

Lastly, create a new instance of the smart contract which will initialize your empty state that holds the assets and allow you to invoke all methods.

Run the following command to create an instance of your deployed contract using the module reference:

concordium-client contract init <YOUR-MODULE-HASH> --sender <YOUR-ADDRESS> --energy 30000 --contract CIS2-Fractionalizer --grpc-port 20000 --grpc-ip node.testnet.concordium.com

Great job! You've successfully built, deployed, and initialized your smart contract. Proceed to the next section.

Last updated