This guide will get you started deploying cw20 smart contracts on a local Injective network running on your computer.
We'll use the cw20-base contract from designed for production use on real networks. cw20-base is a basic implementation of a cw20 compatible contract that can be imported in any custom contract you want to build on. It contains a straightforward but complete implementation of the cw20 spec along with all extensions. cw20-base can be deployed as-is or imported by other contracts.
Prerequisites
Install Go, Rust, and other Cosmwasm dependencies by following the instructions:
Before starting, make sure you have along with recent versions of rustc and cargo installed. Currently, we are testing on Rust v1.58.1+.
You also need to have the wasm32-unknown-unknown target installed as well as the cargo-generate Rust crate.
You can check versions via the following commands:
rustc --version
cargo --version
rustup target list --installed
# if wasm32 is not listed above, run this
rustup target add wasm32-unknown-unknown
# to install cargo-generate, run this
cargo install cargo-generate
injectived
Make sure you have injectived installed locally. You can follow the Install injectivedguide to get injectived and other prerequisites running locally.
Compile CosmWasm Contracts
git clone https://github.com/CosmWasm/cw-plus
cd cw-plus
The docker script builds and optimizes all the CW contracts in the repo, with the compiled contracts located under the artifacts directory. Now we can deploy the cw20_base.wasm contract (cw20_base-aarch64.wasm if compiled on an ARM device).
Upload the CosmWasm Contract to the Chain
# inside the CosmWasm/cw-plus repo
yes 12345678 | injectived tx wasm store artifacts/cw20_base.wasm --from=genesis --chain-id="injective-1" --yes --gas-prices=500000000inj --gas=20000000
The first step of instantiating the contract is to select an address to supply with our initial CW20 token allocation. In our case, we can just use the genesis address since we have the keys already set up, but feel free to generate new addresses and keys.
Make sure you have the private keys for the address you choose—you won't be able to test token transfers from the address otherwise. In addition, the chosen address must be a valid address on the chain (the address must have received funds at some point in the past) and must have balances to pay for gas when executing the contract.
Run the CLI command with code_id1 along with the JSON encoded initialization arguments (with your selected address) and a label (a human-readable name for this contract in lists) to instantiate the contract:
Here are the main differences between a local and testnet development/deployment
When you are using injectived you have to specify the testnet rpc using the node flag --node=https://testnet.sentry.tm.injective.network:443
Instead of using injective-1 as a chainId you should use injective-888 i.e the chain-id flag should now be --chain-id="injective-888"
You can read more on the injectived and how to use it to query/send transactions against testnetUsing injectived.
Once you have injectived installed, you should also
In this step, we will get all CW production template contracts and compile them using the Docker image for compiling multiple contracts (called workspace-optimizer)—see (x86) or (ARM) for latest versions. This process may take a bit of time and CPU power.
Now the address of the instantiated contract can be obtained on
And the contract info metadata can be obtained on or by CLI query
You can use our to get testnet funds to your address,
You can use the to query your transactions and get more details,
You can use the to find information about the codeId of the uploaded smart contracts OR find your instantiated smart contract