The following is a quick guide that shows the basics of deploying a contract to Osmosis. It covers:
The easiest way to setup your localOsmosis is by downloading the automated installer. You can learn more about localOsmosis by reading the README in the official repo.
Run the following and choose option #3.
curl -sL https://get.osmosis.zone/install > i.py && python3 i.py
Inside a separate bash window start your localOsmosis which was installed in ~/localosmosis
cd ~/localosmosis
docker-compose up
You will start seeing LocalOsmosis block activity in your terminal. Keep LocalOsmosis running while you perform the next steps in a new terminal window.
To view the LocalOsmosis wallet information, visit the LocalOsmosis accounts page.
# get the code
git clone https://github.com/CosmWasm/cosmwasm-examples
cd cosmwasm-examples
git fetch
cd contracts/erc20
#compile the wasm contract
rustup default stable
cargo wasm
sudo 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
You now have a cw_erc20.wasm
artifact inside the artifact directory.
Create a key using one of the seeds provided in localOsmosis.
osmosisd keys add <unsafe-test-key-name> --recover
Example test1 key from here:
notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius
cd artifacts
osmosisd tx wasm store cw_erc20.wasm --from <unsafe-test-key-name> --chain-id=<chain-id> \
--gas-prices 0.1uosmo --gas auto --gas-adjustment 1.3 -b block -y
<unsafe-test-key-name> = Name of your local key.
<chain-id> = localosmosis
Save the code_id from the output of the command above.
or save it by running jq
cd artifacts
TX=$(osmosisd tx wasm store cw_erc20.wasm --from <unsafe-test-key-name> --chain-id=localosmosis --gas-prices 0.1uosmo --gas auto --gas-adjustment 1.3 -b block --output json -y | jq -r '.txhash')
CODE_ID=$(osmosisd query tx $TX --output json | jq -r '.logs[0].events[-1].attributes[0].value')
echo $CODE_ID
If this is a brand new localOsmosis instante it should be 1
Type node in the terminal and hit enter to access it. Copy and paste the following:
const initHash = {
name: "Test Coin",
symbol: "TEST",
decimals: 6,
initial_balances: [
{ address: "<validator-self-delegate-address>", amount: "12345678000"},
]
};
<validator-self-delegate-address> = Choose the test1 address
Then copy and paste this:
JSON.stringify(initHash);
The output should be something like:
osmosisd tx wasm instantiate $CODE_ID \
'{"name":"Test Coin","symbol":"TEST","decimals":6,"initial_balances":[{"address":"<validator-self-delegate-address>","amount":"12345678000"}]}' \
--amount 50000uosmo --label "Testcoin erc20" --from <unsafe-test-key-name> --chain-id <chain-id> --gas-prices 0.1uosmo --gas auto --gas-adjustment 1.3 -b block -y
Replace
- <validator-self-delegate-address> : wallet address
- <chain-id> : localosmosis
- <unsafe-test-key-name> : Local key name
CONTRACT_ADDR=$(osmosisd query wasm list-contract-by-code $CODE_ID --output json | jq -r '.contracts[0]')
osmosisd query wasm contract $CONTRACT_ADDR
This guide will be updated and published to the official docs soon.
Credits to: https://cosmwasm.com/