From 880fd3424d5574a9a7fbeb7f9f73e8f98cfeb9f3 Mon Sep 17 00:00:00 2001 From: jurriaan Date: Wed, 13 Nov 2024 18:11:18 +0100 Subject: [PATCH 1/2] fix(docs): apply findings after testing --- .../integrations/ucs01/cosmwasm/index.mdx | 83 ++++++++++++++----- 1 file changed, 60 insertions(+), 23 deletions(-) diff --git a/docs/src/content/docs/integrations/ucs01/cosmwasm/index.mdx b/docs/src/content/docs/integrations/ucs01/cosmwasm/index.mdx index 5e7154d225..ca7b8f633f 100644 --- a/docs/src/content/docs/integrations/ucs01/cosmwasm/index.mdx +++ b/docs/src/content/docs/integrations/ucs01/cosmwasm/index.mdx @@ -33,7 +33,7 @@ ____ :::caution -This example requires a Linux environment. No Windows or MacOS support +This example requires a Linux environment. No Windows or MacOS support. Has been tested on MacOS Sequoia using [OrbStack](https://orbstack.dev) on a fresh Ubuntu 24.10 (ARM) image. ::: @@ -42,6 +42,7 @@ Install the `uniond` binary which you will use to publish the contract and execu +- Cargo.toml - src - lib.rs -- Cargo.toml -- Cargo.lock -- .gitignore ___ @@ -137,7 +153,6 @@ use cosmwasm_std::{ entry_point, to_json_binary, Coin, DepsMut, Env, MessageInfo, Response, StdResult, Uint128, WasmMsg, }; -use std::collections::BTreeMap; #[cw_serde] pub struct InstantiateMsg {} @@ -171,7 +186,7 @@ pub struct TransferMsg { pub memo: String, } -#[entry_point] +#[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( _deps: DepsMut, _env: Env, @@ -181,7 +196,7 @@ pub fn instantiate( Ok(Response::new().add_attribute("action", "instantiate")) } -#[entry_point] +#[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( deps: DepsMut, _env: Env, @@ -279,11 +294,16 @@ export WALLET_NAME="throwaway" Let's create a new wallet and fund it ```sh frame="none" -uniond keys add $WALLET_NAME \ +$HOME/uniond keys add $WALLET_NAME \ --home /home/$USER/.union \ --keyring-backend test ``` -Save the mnemonic in a safe place. +Save the mnemonic and address in a safe place + +Set the WALLET_ADDRESS +```sh frame="none" +WALLET_ADDRESS=union1rhvh8ct8lpnplghr0u9e7qazyq2cezlyd7gfn4 +``` To fund the wallet, we will use the faucet. You can find the faucet [here](https://app.union.build/faucet). @@ -292,7 +312,7 @@ curl https://rest.testnet-8.union.build/cosmos/bank/v1beta1/balances/$WALLET_ADD ``` ```sh title="Deploy the contract" -uniond tx wasm store ./build/contract.wasm \ +$HOME/uniond tx wasm store ./build/contract.wasm \ --from $WALLET_NAME \ --gas auto \ --gas-adjustment 1.4 \ @@ -302,18 +322,25 @@ uniond tx wasm store ./build/contract.wasm \ --node $RPC_URL --yes ``` -The above will return a transaction hash at the end, use it to query the transaction to get the `code_id`: +The above will return a transaction hash at the end as `txhash`. Record it: +```sh frame="none" +DEPLOY_TX_HASH=txhash-value-of-previous-command +``` +... and use it to query the transaction to get the `code_id`: ```sh frame="none" -uniond query tx $DEPLOY_TX_HASH --node https://rpc.testnet-8.union.build:443 | rg "_id" +$HOME/uniond query tx $DEPLOY_TX_HASH --node https://rpc.testnet-8.union.build:443 | rg -C 1 "code_id" ``` -Instantiate the contract: +Record the code-id: +```sh frame="none" +CODE_ID=code_id-value-of-previous-command +``` -> `$CODE_ID` is the `code_id` returned from the previous step. +... and instantiate the contract: ```sh frame="none" -uniond \ +$HOME/uniond \ tx wasm instantiate $CODE_ID '{}' \ --label foobar \ --no-admin \ @@ -326,10 +353,20 @@ uniond \ --node $RPC_URL --yes ``` -The above will return a transaction hash at the end, use it to query the transaction to get the `_contract_address`: +The above will return a transaction hash at the end as `txhash`. record it: +```sh frame="none" +INSTANTIATE_TX_HASH=txhash-value-of-previous-command +``` + +... and use it to query the transaction to get the `_contract_address` (you'll see it twice): ```sh frame="none" -query tx $INSTANTIATE_TX_HASH --node https://rpc.testnet-8.union.build:443 | rg "_contract_address" +$HOME/uniond query tx $INSTANTIATE_TX_HASH --node https://rpc.testnet-8.union.build:443 | rg -C 1 "_contract_address" +``` + +Record the contract address +```sh frame="none" +CONTRACT_ADDRESS=_contract_address-value-of-previous-command ``` Now you can execute the contract to transfer assets: @@ -344,7 +381,7 @@ Let's construct the JSON payload for the contract execution. ```json title="payload.json" { "transfer": { - "receiver": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", + "receiver": "d8da6bf26964af9d7eed9e03e53415d37aa96045", "amount": "1", "denom": "muno", "contract_address": "union1m87a5scxnnk83wfwapxlufzm58qe2v65985exff70z95a2yr86yq7hl08h", @@ -356,7 +393,7 @@ Let's construct the JSON payload for the contract execution. Execute the contract: ```sh frame="none" -uniond \ +$HOME/uniond \ tx wasm execute $CONTRACT_ADDRESS "$(jaq -c '.' payload.json)" \ --from $WALLET_NAME \ --gas auto \ @@ -367,7 +404,7 @@ uniond \ --node $RPC_URL --amount 2muno ``` -To see the result of your cross chain transfer, go to this query and replace the sender with yours: [here](https://docs.union.build/reference/graphql/?query=query%20ContractTransfers%20%7B%0A%20%20v1_transfers(%0A%20%20%20%20where%3A%20%7B%0A%20%20%20%20%20%20sender%3A%20%7B%0A%20%20%20%20%20%20%20%20_like%3A%20%22union1ekc5agfsj2mhp2em4a9gxz8hag8uh74fwwzfa752lp2f52w3rrsqvdcxcs%22%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20)%20%7B%0A%20%20%20%20sender%0A%20%20%20%20source_chain_id%0A%20%20%20%20source_timestamp%0A%20%20%20%20source_port_id%0A%20%20%20%20source_channel_id%0A%20%20%20%20source_block_hash%0A%20%20%20%20source_connection_id%0A%20%20%20%20source_transaction_hash%0A%0A%20%20%20%20receiver%0A%20%20%20%20destination_chain_id%0A%20%20%20%20destination_timestamp%0A%20%20%20%20destination_port_id%0A%20%20%20%20destination_channel_id%0A%20%20%20%20destination_block_hash%0A%20%20%20%20destination_connection_id%0A%20%20%20%20destination_transaction_hash%0A%20%20%7D%0A%7D) +To see the result of your cross chain transfer, go to this query and replace the sender with your `$WALLET_ADDRESS`: [here](https://docs.union.build/reference/graphql/?query=query%20ContractTransfers%20%7B%0A%20%20v1_transfers(%0A%20%20%20%20where%3A%20%7B%0A%20%20%20%20%20%20sender%3A%20%7B%0A%20%20%20%20%20%20%20%20_like%3A%20%22union1ekc5agfsj2mhp2em4a9gxz8hag8uh74fwwzfa752lp2f52w3rrsqvdcxcs%22%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20)%20%7B%0A%20%20%20%20sender%0A%20%20%20%20source_chain_id%0A%20%20%20%20source_timestamp%0A%20%20%20%20source_port_id%0A%20%20%20%20source_channel_id%0A%20%20%20%20source_block_hash%0A%20%20%20%20source_connection_id%0A%20%20%20%20source_transaction_hash%0A%0A%20%20%20%20receiver%0A%20%20%20%20destination_chain_id%0A%20%20%20%20destination_timestamp%0A%20%20%20%20destination_port_id%0A%20%20%20%20destination_channel_id%0A%20%20%20%20destination_block_hash%0A%20%20%20%20destination_connection_id%0A%20%20%20%20destination_transaction_hash%0A%20%20%7D%0A%7D) ___ From fc473e170de6e408bed2c17931e3dfdf398d5efe Mon Sep 17 00:00:00 2001 From: jurriaan Date: Wed, 13 Nov 2024 18:54:47 +0100 Subject: [PATCH 2/2] fix(docs): apply findings after testing --- docs/src/content/docs/integrations/ucs01/cosmwasm/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/content/docs/integrations/ucs01/cosmwasm/index.mdx b/docs/src/content/docs/integrations/ucs01/cosmwasm/index.mdx index ca7b8f633f..9680d8b48e 100644 --- a/docs/src/content/docs/integrations/ucs01/cosmwasm/index.mdx +++ b/docs/src/content/docs/integrations/ucs01/cosmwasm/index.mdx @@ -302,7 +302,7 @@ Save the mnemonic and address in a safe place Set the WALLET_ADDRESS ```sh frame="none" -WALLET_ADDRESS=union1rhvh8ct8lpnplghr0u9e7qazyq2cezlyd7gfn4 +WALLET_ADDRESS=union1... ``` To fund the wallet, we will use the faucet. You can find the faucet [here](https://app.union.build/faucet).