Initialise the Contract
It's go time!
CosmWasm Smart Contracts take their arguments as serialised JSON. This can be created a number of ways, but as we showed in the previous examples, it may well be easiest to use the node command line, if that is available to you.
There is a Typescript helpers file for most contracts, and extensions for CosmJS, but at the time of writing, they are broken. This will no doubt be fixed soon, providing an alternative way of interacting with contracts other than the CLI.
To use the node REPL, type node in the terminal.
1
const initobj = {
2
admins: ["<your-validator-self-delegate-key>"],
3
mutable: false
4
};
5
6
< undefined
7
8
JSON.stringify(initobj);
9
10
< '{"admins":["<your-validator-self-delegate-key>"],"mutable":false}'
Copied!
With these encoded arguments, you can now instantiate the contract, using the code_id from the previous step.
1
junod tx wasm instantiate <code-id> '{"admins":["<your-validator-self-delegate-key>"],"mutable":false}' --amount 50000ujuno --label "CW1 example contract" --from <your-key> --chain-id <chain-id> --gas auto -y
Copied!
Once the contract is instantiated, you can find out its contract address:
1
junod query wasm list-contract-by-code <code-id>
Copied!
You will need this to interact with the contract.
Last modified 5d ago
Copy link