Guide
In this guide, we'll go over how to upload a smart contract.
What's a WASM file?​
When a smart contract is going to be deployed on the Juno network, a WASM file must be generated first. WASM, web assembly, is a portable binary-code format popular among blockchain applications.
That's because the code will be interpreted by different machines and there is a need for a common understanding of a code, like a protocol.
Generate a WASM File​
To generate a WASM file, you must have an access to the smart contract code.
It can be either a code you wrote or a code you cloned/forked from someone else.
The folder structure of a smart contract should look similar to this:
cw-contract/
├── .cargo/
│ └── config
├── .circleci/
│ └── config.yml
├── .github/workflows/
│ └── Basic.yml
├── examples/
│ └── schema.rs
├── schema/
├── src/
│ ├── state.rs
│ ├── contract.rs
│ ├── lib.rs
│ ├── msg.rs
│ └── error.rs
└── target/
There are a few ways to generate a WASM file.
- Unoptimised:
cargo wasm
- Optimized (Docker must be installed):
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.12.6
Be sure to execute the generation code at the root of the folder.
warning
Unoptimized WASM files might get too big for JunoTools to deploy and thus fail or request more gas fees than usual.
Try to build an optimized WASM file when possible.
When the file is generated, simply head to the Contract Upload page, choose the WASM file, and press upload contract.
Congrats! You have successfully learned how to upload a contract to the Juno network!