Download, Compile, Store
Now we're going to download a contract, compile it, and upload it to the Juno chain.

Download

We're going to grab the cosmwasm-examples repo and compile our chosen contract.
1
# get the code
2
git clone https://github.com/CosmWasm/cosmwasm-examples
3
cd cosmwasm-examples
4
git fetch
5
git checkout v0.10.0 # current at time of writing
6
cd contracts/erc20
Copied!

Compile

We can compile our contract like so:
1
# compile the wasm contract with stable toolchain
2
rustup default stable
3
cargo wasm
Copied!
However, we want to create an optimised version to limit gas usage, so we're going to run:
1
sudo docker run --rm -v "$(pwd)":/code \
2
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
3
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
4
cosmwasm/rust-optimizer:0.11.4
Copied!
This will result in an artifact called cw_erc20.wasm being created in the artifacts directory.

Uploading

You can now upload, or 'store' this to the chain via your local node.
1
cd artifacts
2
junod tx wasm store cw_erc20.wasm --from <your-key> --chain-id=<chain-id> --gas auto
Copied!
You will need to look in the output for this command for the code ID of the contract. In the JSON, it will look like {"key":"code_id","value":"6"} in the output.
Alternatively, you can capture the output of the command run above, by doing these steps instead, and use the jq tool installed earlier to get the code_id value:
1
cd artifacts
2
RES=$(junod tx wasm store cw_erc20.wasm --from <your-key> --chain-id=<chain-id> --gas auto -y)
3
CODE_ID=$(echo $RES | jq -r '.logs[0].events[0].attributes[-1].value')
Copied!
You can now see this value with:
1
echo $CODE_ID
Copied!
Last modified 3mo ago
Copy link