{"id":19701208,"url":"https://github.com/alexanderc/cosmwasm-sylvia-counting-contract","last_synced_at":"2025-04-29T13:33:01.116Z","repository":{"id":205121310,"uuid":"712858671","full_name":"AlexanderC/cosmwasm-sylvia-counting-contract","owner":"AlexanderC","description":"CosmWasm/Sylvia counting contract w/ IBC enabled (Cosmos, Rust, CosmWasm, Sylvia)","archived":false,"fork":false,"pushed_at":"2023-11-21T09:30:44.000Z","size":388,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T17:36:13.048Z","etag":null,"topics":["cosmos-sdk","cosmwasm","ibc","sylvia"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexanderC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-01T10:49:48.000Z","updated_at":"2023-11-22T10:58:32.000Z","dependencies_parsed_at":"2023-11-15T09:27:57.605Z","dependency_job_id":"34d456ec-8f7e-4e61-adf8-0e46b15fa50c","html_url":"https://github.com/AlexanderC/cosmwasm-sylvia-counting-contract","commit_stats":{"total_commits":14,"total_committers":1,"mean_commits":14.0,"dds":0.0,"last_synced_commit":"cb37553247ae7e1428f52a5e6a18fe7c0e40c3bb"},"previous_names":["alexanderc/cosmwasm-sylvia-test","alexanderc/cosmwasm-sylvia-counting-contract"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexanderC%2Fcosmwasm-sylvia-counting-contract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexanderC%2Fcosmwasm-sylvia-counting-contract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexanderC%2Fcosmwasm-sylvia-counting-contract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexanderC%2Fcosmwasm-sylvia-counting-contract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexanderC","download_url":"https://codeload.github.com/AlexanderC/cosmwasm-sylvia-counting-contract/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251509821,"owners_count":21600710,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cosmos-sdk","cosmwasm","ibc","sylvia"],"created_at":"2024-11-11T21:08:13.072Z","updated_at":"2025-04-29T13:33:00.133Z","avatar_url":"https://github.com/AlexanderC.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CosmWasm/Sylvia counting contract w/ IBC enabled (Cosmos, Rust, CosmWasm, Sylvia)\n\nThis repository contains counting contract created during the study of CosmWasm/Sylvia and IBC based contracts development for Cosmos blockchains written using Rust.\n\n\u003e The IBC implementation attempt on Sylvia is based on https://github.com/0xekez/cw-ibc-example as at the time of\n\u003e writing this the https://cosmwasm.github.io/sylvia-book/ibc.html#ibc section is empty.\n\u003e Moreover Sylvia does NOT support natively IBC, see maintainer comment https://github.com/CosmWasm/sylvia/issues/19#issuecomment-1792586062.\n\n## Preface\n\nRust library skeleton generated using:\n\n```\ncargo new --lib ./counting-contract\ncd ./counting-contract\ncargo check\n```\n\n## Prerequisites\n\nBesides regular dependencies like Go, Rust and CosmWasm binaries, we need additional software to deploy and operate the contracts...\n\nAs the IBC relayer is used https://hermes.informal.systems.\n\n```\ncargo install ibc-relayer-cli --bin hermes --locked\n```\n\nTo deploy and operate the contracts on Juno we need `junod` (https://docs.junonetwork.io/validators/getting-setup):\n\n```\ngit clone https://github.com/CosmosContracts/juno\ncd juno\ngit fetch --all --tags\ngit checkout v18.0.0-alpha.2\nmake install\n```\n\nTo deploy and operate the contracts on Osmosis we need `osmosisd` (https://docs.osmosis.zone/cosmwasm/testnet/cosmwasm-deployment#setup-osmosis-testnet):\n\n```\ncurl -sL https://get.osmosis.zone/install \u003e i.py \u0026\u0026 python3 i.py\n```\n\n\u003e Choose option #2 (Client Node) and #2 (Testnet) in order. You may run with sudo but don't forget to chown afterwards...\n\n## Build\n\n\u003e Aliases in `.cargo/config`\n\nBuilt contract to artifacts:\n\n```\n// cargo wasm-debug\ncargo wasm\ncosmwasm-check target/wasm32-unknown-unknown/release/counting_contract.wasm\n```\n\nGenerate contract schemas:\n\n```\ncargo schema\n```\n\nBuild optimized deployment version (**run in repository root!**):\n\n```\ndocker run --rm -v \"$(pwd)\":/code \\\n  --mount type=volume,source=\"$(basename \"$(pwd)\")_cache\",target=/code/target \\\n  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \\\n  cosmwasm/rust-optimizer:0.14.0\ncosmwasm-check artifacts/counting_contract.wasm\n```\n\n## Unit Testing\n\n```\ncargo test\n```\n\n## Deploying (Testnet)\n\nFirst we need to configure Juno node:\n\n```\njunod config node https://juno-testnet-rpc.polkachu.com:443\njunod config chain-id uni-6\n```\n\n\u003e You may explore the testnet tools here: https://polkachu.com/testnets/juno\n\nWe will create two Juno wallets first:\n\n```\njunod keys add wallet\n// wallet address: juno1dkgs7ymhmnnu3c874wyaakh03jn9l3fes52jxg\njunod keys add wallet2\n// wallet2 address: juno1qqkj8r6hfqh93jq65jermsmq288je7873jmjh5\njunod keys add wallet-ibc --output json \u003e .wallet.junod\n// wallet-ibc address: juno1hhfw77usyd6t8y9xuj6xlmqq5nkuqyc9vkcsha\n// wallet-ibc explorer: https://www.mintscan.io/juno-testnet/address/juno1hhfw77usyd6t8y9xuj6xlmqq5nkuqyc9vkcsha\n```\n\n\u003e Latest faucet working is `https://faucet.reece.sh/uni-6/{replace-with-your-address}` (e.g. https://faucet.reece.sh/uni-6/juno1hhfw77usyd6t8y9xuj6xlmqq5nkuqyc9vkcsha).\n\n\u003e May you want to query wallet balances use `junod query bank balances juno1dkgs7ymhmnnu3c874wyaakh03jn9l3fes52jxg`\n\n...and create two Osmosis wallets:\n\n```\nosmosisd keys add wallet\n// wallet address: osmo1kzd8am90ktcye0yrf7p6z5z4lgz3pg6sp9qu6s\nosmosisd keys add wallet2\n// wallet2 address: osmo1xdk392u7y36s4fe06eu04e6mt7x4kt5793takz\nosmosisd keys add wallet-ibc --output json \u003e .wallet.osmosis\n// wallet-ibc address: osmo1fywaxmn73dja3kmd5deuv2gf46ktna6f6el3aw\n// wallet-ibc explorer: https://testnet.mintscan.io/osmosis-testnet/account/osmo1fywaxmn73dja3kmd5deuv2gf46ktna6f6el3aw\n```\n\n\u003e The faucet address is `https://faucet.testnet.osmosis.zone`\n\n\u003e May you want to query wallet balances use `osmosisd query bank balances osmo1kzd8am90ktcye0yrf7p6z5z4lgz3pg6sp9qu6s`\n\n**We will deploy the contract to `uni-6` and `osmo-test-5` using `junod` binary.**\n\nFirst we upload the code:\n\n```\n// Chain A\njunod tx wasm store artifacts/counting_contract.wasm --chain-id=uni-6 --from wallet -y --gas=auto --gas-adjustment=1.15 --gas-prices=\"0.025ujunox\" -b sync\n\n// Chain B\nosmosisd tx wasm store artifacts/counting_contract.wasm --chain-id=osmo-test-5 --from wallet -y --gas=auto --gas-adjustment=1.15 --gas-prices=\"0.025uosmo\" -b sync\n```\n\n\u003e To get contract code ID you must query the `txhash`, e.g.: `junod q tx 0C911A8A7790470297CB5A17C2198F2FD5321BCA9DF8B92D62781745EEBD3F37 --output=json` and `osmosisd q tx 8A8E552A55D24D0068647BEE6B03E04EC069272F341467955E1FABE37720BAFB --output=json`\n\nThan we instantiate the contracts on both networks:\n\n```\n// Chain A\nCODE_ID_A=3883\njunod tx wasm instantiate \"$CODE_ID_A\" '{\"count\":0,\"admins\":[]}' --label \"counting-contract\" --chain-id=uni-6 -y --from wallet --admin wallet --gas=auto --gas-adjustment=1.15 --gas-prices=\"0.025ujunox\"\n\n// Chain B\nCODE_ID_B=5085\nosmosisd tx wasm instantiate \"$CODE_ID_B\" '{\"count\":0,\"admins\":[]}' --label \"counting-contract\" --chain-id=osmo-test-5 -y --from wallet --admin wallet --gas=auto --gas-adjustment=1.15 --gas-prices=\"0.025uosmo\"\n```\n\n\u003e To get initiation info you must query the `txhash`, e.g.: `junod q tx BF1862AD34C328A30D0CE99DD684E71E015FB2E95D29D55AD603B24A7324EB14 --output=json` and `osmosisd q tx 197AC7FA66DA0E5E35EDE2F822F8DC6A54DDD5936D28B7812DC2DC7DE3A41414 --output=json`\n\nNow we need to query the instantiated contracts:\n\n```\n// Chain A\nCONTRANT_ADDRESS_A=juno1wjjx974u9j80wazvxsx3ukr85jmazk7szk37qn0kmelu98gl620qwxqxz0\njunod query wasm contract \"$CONTRANT_ADDRESS_A\"\n\n// Chain B\nCONTRANT_ADDRESS_B=osmo1xz00vhlm7e3ysj9f2v3jtcjpqvectwgdkkxuau8rw290ys087s6qtk24hy\nosmosisd query wasm contract \"$CONTRANT_ADDRESS_B\"\n```\n\n\u003e Look at `ibc_port_id` in the output. Should the contract have IBC entry points enabled it will contain a value e.g. `wasm.juno1wjjx974u9j80wazvxsx3ukr85jmazk7szk37qn0kmelu98gl620qwxqxz0`\n\nBefore starting the relayer we need to configure it:\n\n```\nmkdir ~/.hermes \u0026\u0026 touch ~/.hermes/config.toml\ncat .hermes.config.toml \u003e ~/.hermes/config.toml\nhermes config validate\n```\n\n...and generate wallets for relaying:\n\n```\nhermes keys add --chain uni-6 --key-file .wallet.junod\nhermes keys add --chain osmo-test-5 --key-file .wallet.osmosis\n```\n\n\u003e May you want to query balances use `hermes keys balance --chain osmo-test-5`\n and `hermes keys balance --chain uni-6`. `.wallet.*` contain sensitive data— make sure you keep them in `.gitignore`!\n\nAfterwards, in order to get IBC running we need to create the relayer channel:\n\n```\nIBC_PORT_A=wasm.juno1wjjx974u9j80wazvxsx3ukr85jmazk7szk37qn0kmelu98gl620qwxqxz0\nIBC_PORT_B=wasm.osmo1xz00vhlm7e3ysj9f2v3jtcjpqvectwgdkkxuau8rw290ys087s6qtk24hy\nhermes create channel --a-chain uni-6 --b-chain osmo-test-5 --a-port \"$IBC_PORT_A\" --b-port \"$IBC_PORT_B\" --channel-version counter-contract-1 --new-client-connection\n```\n\nAfter successfully running `hermes create channel` you should see smth like:\n\n```json\nSUCCESS Channel {\n    ordering: Unordered,\n    a_side: ChannelSide {\n        chain: BaseChainHandle {\n            chain_id: ChainId {\n                id: \"uni-6\",\n                version: 6,\n            },\n            runtime_sender: Sender { .. },\n        },\n        client_id: ClientId(\n            \"07-tendermint-691\",\n        ),\n        connection_id: ConnectionId(\n            \"connection-782\",\n        ),\n        port_id: PortId(\n            \"wasm.juno1wjjx974u9j80wazvxsx3ukr85jmazk7szk37qn0kmelu98gl620qwxqxz0\",\n        ),\n        channel_id: Some(\n            ChannelId(\n                \"channel-839\",\n            ),\n        ),\n        version: Some(\n            Version(\n                \"counter-contract-1\",\n            ),\n        ),\n    },\n    b_side: ChannelSide {\n        chain: BaseChainHandle {\n            chain_id: ChainId {\n                id: \"osmo-test-5\",\n                version: 5,\n            },\n            runtime_sender: Sender { .. },\n        },\n        client_id: ClientId(\n            \"07-tendermint-1424\",\n        ),\n        connection_id: ConnectionId(\n            \"connection-1329\",\n        ),\n        port_id: PortId(\n            \"wasm.osmo1xz00vhlm7e3ysj9f2v3jtcjpqvectwgdkkxuau8rw290ys087s6qtk24hy\",\n        ),\n        channel_id: Some(\n            ChannelId(\n                \"channel-4347\",\n            ),\n        ),\n        version: Some(\n            Version(\n                \"counter-contract-1\",\n            ),\n        ),\n    },\n    connection_delay: 0ns,\n}\n```\n\nBefore starting the channel relayer you need to update `~/.hermes/config.toml` and add proper channel list (see create channel command output— to allow created channels):\n\n```\n// UPDATE [[chains]]: list = [[\"wasm.juno1wjjx974u9j80wazvxsx3ukr85jmazk7szk37qn0kmelu98gl620qwxqxz0\", \"channel-839\"], [\"wasm.osmo1xz00vhlm7e3ysj9f2v3jtcjpqvectwgdkkxuau8rw290ys087s6qtk24hy\", \"channel-4347\"]]\ncat .hermes.config.toml \u003e ~/.hermes/config.toml\nhermes config validate\nhermes start\n```\n\n## Interacting with contracts (Testnet)\n\nCheck our counters states on both chains:\n\n```\n// Assuming addresses were set during the steps above...\n// CONTRANT_ADDRESS_A=juno1wjjx974u9j80wazvxsx3ukr85jmazk7szk37qn0kmelu98gl620qwxqxz0\n// CONTRANT_ADDRESS_B=osmo1xz00vhlm7e3ysj9f2v3jtcjpqvectwgdkkxuau8rw290ys087s6qtk24hy\n\njunod query wasm contract-state smart \"$CONTRANT_ADDRESS_A\" '{\"count\": {}}' --chain-id=uni-6\njunod query wasm contract-state smart \"$CONTRANT_ADDRESS_A\" '{\"ibc_count\": {\"channel\": \"channel-839\"}}' --chain-id=uni-6\n\nosmosisd query wasm contract-state smart \"$CONTRANT_ADDRESS_B\" '{\"count\": {}}' --chain-id=osmo-test-5\nosmosisd query wasm contract-state smart \"$CONTRANT_ADDRESS_B\" '{\"ibc_count\": {\"channel\": \"channel-4347\"}}' --chain-id=osmo-test-5\n```\n\nLet's try to increment counts directly (on Juno):\n\n```\njunod tx wasm execute \"$CONTRANT_ADDRESS_A\" '{\"increment_count\": {}}' --chain-id=uni-6 --from wallet -y --gas=auto --gas-adjustment=1.3 --gas-prices=\"0.025ujunox\" -b sync\n// Now query the contract on Juno and check results\njunod query wasm contract-state smart \"$CONTRANT_ADDRESS_A\" '{\"count\": {}}' --chain-id=uni-6\njunod query wasm contract-state smart \"$CONTRANT_ADDRESS_A\" '{\"ibc_count\": {\"channel\": \"channel-4347\"}}' --chain-id=uni-6\n```\n\nAnd use IBC called on Osmosis contract (local `channel_id=channel-4347`) to increment Juno contract count... remotely!:\n\n```\nosmosisd tx wasm execute \"$CONTRANT_ADDRESS_B\" '{\"increment_ibc_count\": {\"channel\": \"channel-4347\"}}' --chain-id=osmo-test-5 -y --from wallet --gas=auto --gas-adjustment=1.3 --gas-prices=\"0.025uosmo\"\n// Now query the contract on Juno and check results\njunod query wasm contract-state smart \"$CONTRANT_ADDRESS_A\" '{\"ibc_count\": {\"channel\": \"channel-839\"}}' --chain-id=uni-6\n```\n\n\u003e You might do call increment vice-versa, from Juno using `junod tx wasm execute \"$CONTRANT_ADDRESS_A\" '{\"increment_ibc_count\": {\"channel\": \"channel-839\"}}' --chain-id=uni-6 --from wallet -y --gas=auto --gas-adjustment=1.3 --gas-prices=\"0.025ujunox\" -b sync`\n\n...now let's decrease count in Juno contract through Osmosis:\n\n```\nosmosisd tx wasm execute \"$CONTRANT_ADDRESS_B\" '{\"decrement_ibc_count\": {\"channel\": \"channel-4347\"}}' --chain-id=osmo-test-5 -y --from wallet --gas=auto --gas-adjustment=1.3 --gas-prices=\"0.025uosmo\"\n// Now query the contract on Juno and check results\njunod query wasm contract-state smart \"$CONTRANT_ADDRESS_A\" '{\"ibc_count\": {\"channel\": \"channel-839\"}}' --chain-id=uni-6\n```\n\n...after all let's check what happened to Osmosis IBC related states:\n\n```\nosmosisd query wasm contract-state smart \"$CONTRANT_ADDRESS_B\" '{\"ibc_count\": {\"channel\": \"channel-4347\"}}' --chain-id=osmo-test-5\n```\n\n\u003e In case your relayer was not working you might have some `ibc_channel_timeouts` stored... If not— stop relayer for a while and repeat the steps above; you will see NO increase in counter states on remote contract and `ibc_channel_timeouts` number increasing with every call to `increment_ibc_count` or `decrement_ibc_count`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexanderc%2Fcosmwasm-sylvia-counting-contract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexanderc%2Fcosmwasm-sylvia-counting-contract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexanderc%2Fcosmwasm-sylvia-counting-contract/lists"}