Last active
January 5, 2023 05:12
-
-
Save the-frey/39549a9a58dc91c7a57bb5f0ccb4f3f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# assuming you already have cargo | |
# check with | |
cargo version | |
# then install | |
cargo install cargo-generate --features vendored-openssl | |
cargo install cargo-run-script | |
# now you can generate | |
cargo generate --git https://github.com/InterWasm/cw-template.git --name dummies_example | |
# in another tab, you can run juno | |
# pull the repo & checkout main first | |
STAKE_TOKEN=ujunox UNSAFE_CORS=true docker-compose up | |
# then before the next steps you may find it easier to have txflags set | |
TXFLAG="--gas-prices 0.1ujunox --gas auto --gas-adjustment 1.3 -y -b block --chain-id testing --node http://localhost:26657/" | |
# if you are on an M1 mac you will have to run those commands _inside_ the container | |
# notice that juno_node_1 is the default | |
# on e.g. a linux box with juno installed | |
# the correct ports will be open to talk to juno running in docker | |
# even so, proably easier to use $BINARY as below | |
BINARY="docker exec -i juno_node_1 junod" | |
# in your cw repo - AMD/Intel version | |
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 | |
# on M1 mac/ARM - note this will not work in prod! | |
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-arm64:0.12.6 | |
# look for artifact | |
ls -la artifacts | |
# copy to the container | |
# the name will depend on whether you were AMD or ARM | |
docker cp artifacts/<wasm_binary_name>.wasm juno_node_1:/<wasm_binary_name>.wasm | |
# store | |
# note that validator key is added automagically | |
CONTRACT_CODE=$($BINARY tx wasm store "/<wasm_binary_name>.wasm" --from validator $TXFLAG --output json | jq -r '.logs[0].events[-1].attributes[0].value') | |
echo "Stored: $CONTRACT_CODE" | |
# if you wanted to provision the default user: | |
echo "clip hire initial neck maid actor venue client foam budget lock catalog sweet steak waste crater broccoli pipe steak sister coyote moment obvious choose" | $BINARY keys add test-user --recover --keyring-backend test | |
# instantiate | |
INIT='{ | |
"count": 42 | |
}' | |
# now we can instantiate | |
$BINARY tx wasm instantiate $CONTRACT_CODE "$INIT" --from "validator" --label "my first contract" $TXFLAG --no-admin | |
# the previous command will return the contract code, but we can query it: | |
$BINARY q wasm list-contract-by-code 1 | |
# query the contract address | |
CONTRACT_ADDRESS=$($BINARY q wasm list-contract-by-code $CONTRACT_CODE --output json | jq -r '.contracts[-1]') | |
echo $CONTRACT_ADDRESS | |
# query state - should return 42 | |
$BINARY q wasm contract-state smart $CONTRACT_ADDRESS '{"get_count":{}}' --output json | |
# execute changes state - will inc to 43 | |
$BINARY tx wasm execute $CONTRACT_ADDRESS '{"increment":{}}' --from test-user $TXFLAG | |
# query state again - should return 43 | |
$BINARY q wasm contract-state smart $CONTRACT_ADDRESS '{"get_count":{}}' --output json | |
# but we fear change, so we reset it to 42 | |
$BINARY tx wasm execute $CONTRACT_ADDRESS '{"reset":{"count": 42}}' --from test-user $TXFLAG | |
# query state a final time - it is now 42 | |
$BINARY q wasm contract-state smart $CONTRACT_ADDRESS '{"get_count":{}}' --output json | |
I think you're using a newer version of the cosmwasm template than the one in our tutorial so the API and commands have changed slightly (as the error seems to suggest that the schema is the 1.1 API, not the 1.0 API from the tutorial)
Oops my bad! I noticed it now. Thanks @the-frey !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@the-frey Hi, I am trying to run the
cosmwasm/rust-optimizer
container (Intel). However, I am getting this error while running the command: