Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docs): apply findings after testing #3261

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 60 additions & 23 deletions docs/src/content/docs/integrations/ucs01/cosmwasm/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

:::

Expand All @@ -42,6 +42,7 @@ Install the `uniond` binary which you will use to publish the contract and execu
<Code
code={
`
cd $HOME
# determine your system architecture
RELEASE="uniond-release-$(uname -m)-linux"
# get the version we want to install
Expand All @@ -66,6 +67,7 @@ Install Rust

```sh frame="none"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
. "$HOME/.cargo/env"
```

Install CLI packages: `ripgrep` and `jaq`
Expand All @@ -74,17 +76,23 @@ Install CLI packages: `ripgrep` and `jaq`
cargo install ripgrep jaq
```

Create a new directory and initialize a git repository
Install development tools
```sh frame="none"
sudo apt update
sudo apt install jq tree git build-essential
```

Install wasm packages: `wasm-pack` and `wasm-opt`

```sh frame="none"
mkdir example-ucs01-cosmwasm && cd example-ucs01-cosmwasm
git init .
cargo install wasm-pack wasm-opt
```

Set up a new Rust project

```sh frame="none"
cargo new --lib example-ucs01-cosmwasm
cd example-ucs01-cosmwasm
```

Add the required dependencies to the `Cargo.toml` file
Expand All @@ -104,19 +112,27 @@ cosmwasm-std = { version = "2.1.4", default-features = false, features = ["std",
serde = { version = "1.0.210", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.64", default-features = false }

[features]
library = []

[profile.release]
opt-level = "z"
strip = true
```

Configure Rust-nightly

```sh frame="none"
rustup override set nightly-2024-10-11
rustup component add rust-src --toolchain nightly-2024-10-11-aarch64-unknown-linux-gnu
```

Our end directory structure will look like this:

<FileTree>
- Cargo.toml
- src
- lib.rs
- Cargo.toml
- Cargo.lock
- .gitignore
</FileTree>

___
Expand All @@ -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 {}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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).

Expand All @@ -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 \
Expand All @@ -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 \
Expand All @@ -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:
Expand All @@ -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",
Expand All @@ -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 \
Expand All @@ -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)

___