cw20 smart contracts on a local Injective network running on your computer.
We’ll use the cw20-base contract from CosmWasm’s collection of specifications and contracts 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 haverustup 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:
injectived
Make sure you haveinjectived installed locally. You can follow the install injectived guide to get injectived and other prerequisites running locally.
Once you have injectived installed, you should also start a local chain instance.
Compile CosmWasm Contracts
In this step, we will get all CW production template contracts and compile them using the CosmWasm Rust Optimizer Docker image for compiling multiple contracts (calledworkspace-optimizer)—see here (x86) or here (ARM) for latest versions. This process may take a bit of time and CPU power.
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
txhash to verify the contract was indeed deployed.
code_id of 1 for the contract
Instantiate the Contract
Before instantiating the contract, let’s take a look at the CW-20 contract function signature forinstantiate.
InstantiateMsg parameter which contains the token name, symbol, decimals, and other details.
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.
code_id 1 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:
http://localhost:10337/swagger/#/Query/ContractsByCode
And the contract info metadata can be obtained on http://localhost:10337/swagger/#/Query/ContractInfo or by CLI query
Querying the contract
The entire contract state can be queried with:Transferring Tokens
Testnet Development
Here are the main differences between alocal and testnet development/deployment
- You can use our Injective Testnet Faucet to get testnet funds to your address,
- You can use the Injective Testnet Explorer to query your transactions and get more details,
- When you are using
injectivedyou have to specify thetestnetrpc using thenodeflag--node=https://testnet.sentry.tm.injective.network:443 - Instead of using
injective-1as achainIdyou should useinjective-888i.e thechain-idflag should now be--chain-id="injective-888" - You can use the Injective Testnet Explorer to find information about the
codeIdof the uploaded smart contracts OR find your instantiated smart contract
injectived and how to use it to query/send transactions against testnet in the using injectived guide.