From 982cacf37ebf656a6504da23202b455b52b05af4 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Fri, 1 Aug 2025 13:58:06 +0300 Subject: [PATCH 1/4] add CLI to sidebar --- src/pages/reference/_meta.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pages/reference/_meta.json b/src/pages/reference/_meta.json index 8b34d3198..149d8171e 100644 --- a/src/pages/reference/_meta.json +++ b/src/pages/reference/_meta.json @@ -7,6 +7,10 @@ "title": "RPC & Contracts", "description": "RPC/API endpoints and protocol contract addresses" }, + "cli": { + "title": "CLI", + "description": "Command line interface for building universal apps" + }, "localnet": { "title": "Localnet", "readTime": "30 min", From e202ba5f4952a6eaa6f45c65a9d171f9a6e2ded6 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Fri, 1 Aug 2025 17:47:39 +0300 Subject: [PATCH 2/4] wip --- src/pages/developers/tutorials/solana.mdx | 138 ++++++++++++---------- 1 file changed, 75 insertions(+), 63 deletions(-) diff --git a/src/pages/developers/tutorials/solana.mdx b/src/pages/developers/tutorials/solana.mdx index 5066f3e99..86b86daeb 100644 --- a/src/pages/developers/tutorials/solana.mdx +++ b/src/pages/developers/tutorials/solana.mdx @@ -37,53 +37,74 @@ This command brings up the local development environment with ZetaChain and Solana: ```bash -yarn zetachain localnet start +npx zetachain localnet start --chains solana ``` Leave this running in one terminal window. ## Compile and Deploy an Example Universal Contract -In a new terminal window, compile and deploy the universal contract: - -```bash -npx hardhat compile --force -npx hardhat deploy --name Universal --network localhost --gateway 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 +``` +GATEWAY_ZETACHAIN=$(jq -r '.["31337"].contracts[] | select(.contractType == "gateway") | .address' ~/.zetachain/localnet/registry.json) && echo $GATEWAY_ZETACHAIN ``` -You will see a confirmation with your contract address: +``` +PRIVATE_KEY=$(jq -r '.private_keys[0]' ~/.zetachain/localnet/anvil.json) && echo $PRIVATE_KEY +``` ``` -🚀 Successfully deployed "Universal" contract on localhost. -📜 Contract address: 0x8198f5d8F8CfFE8f9C413d98a0A55aEB8ab9FbB7 +MNEMONIC="grape subway rack mean march bubble carry avoid muffin consider thing street" ``` -Keep track of the contract address for later (in this example, -`0x8198f5d8F8CfFE8f9C413d98a0A55aEB8ab9FbB7`). +In a new terminal window, compile and deploy the universal contract: + +```bash +UNIVERSAL=$(forge create Universal \ + --rpc-url http://localhost:8545 \ + --private-key $PRIVATE_KEY \ + --evm-version paris \ + --broadcast \ + --json \ + --constructor-args $GATEWAY_ZETACHAIN | jq -r .deployedTo) && echo $UNIVERSAL +``` ## Deposit Deposit SOL tokens from Solana to ZetaChain: ``` -npx hardhat localnet:solana-deposit \ - --receiver 0x8198f5d8F8CfFE8f9C413d98a0A55aEB8ab9FbB7 \ - --amount 0.1 +npx zetachain solana deposit \ + --recipient $UNIVERSAL \ + --mnemonic $MNEMONIC \ + --amount 0.01 \ + --chain-id 902 ``` ---receiver: Universal contract address on ZetaChain. +## Call ---amount: Amount of SOL to deposit. +Call the deployed universal contract: + +```bash +npx zetachain solana call \ + --recipient $UNIVERSAL \ + --mnemonic $MNEMONIC \ + --chain-id 902 \ + --types string \ + --values hello +``` ## Deposit and Call Deposit tokens and simultaneously call the deployed universal contract: ```bash -npx hardhat localnet:solana-deposit-and-call \ - --receiver 0x8198f5d8F8CfFE8f9C413d98a0A55aEB8ab9FbB7 \ - --amount 0.1 \ - --types '["string"]' hello +npx zetachain solana deposit-and-call \ + --recipient $UNIVERSAL \ + --mnemonic $MNEMONIC \ + --amount 0.01 \ + --chain-id 902 \ + --types string \ + --values hello ``` This command deposits tokens and triggers the universal contract function with @@ -94,12 +115,13 @@ the argument "hello". Withdraw tokens from ZetaChain back to Solana: ```bash -npx hardhat zetachain-withdraw \ - --gateway-zeta-chain 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 \ +npx zetachain z withdraw \ --receiver DrexsvCMH9WWjgnjVbx1iFf3YZcKadupFmxnZLfSyotd \ - --network localhost \ - --zrc20 0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891 \ - --amount 0.1 + --zrc20 0x777915D031d1e8144c90D025C594b3b8Bf07a08d \ + --amount 0.1 \ + --rpc http://localhost:8545 \ + --gateway $GATEWAY_ZETACHAIN \ + --private-key $PRIVATE_KEY ``` - `--gateway-zeta-chain`: Address of the ZetaChain gateway. @@ -130,60 +152,50 @@ Set the SPL-20 USDC address. You can find this address in a table in the output of `localnet`: ```bash -USDC_SPL=3Kx5SY7SwzdUZSorLVSpPgxBL8DZFiu8mg4FWduu2tQp +USDC_SPL=$(jq -r '.["902"].contracts[] | select(.contractType == "userTokenAccountUSDC") | .address' ~/.zetachain/localnet/registry.json) && echo $USDC_SPL ``` ```bash -cd solana && anchor build && npx ts-node setup/main.ts "$USDC_SPL" && cd - +cd solana +``` + +``` +anchor build +``` + +``` +PROGRAM_ID=$(solana program deploy \ + --program-id setup/connected-keypair.json target/deploy/connected.so \ + --url localhost \ + --output json | jq -r .programId) && echo $PROGRAM_ID ``` After running this, you should see output indicating that the program was successfully deployed, such as: ``` -Connected program deployment output: Program Id: 9BjVGjn28E58LgSi547JYEpqpgRoo1TErkbyXiRSNDQy +Program Id: 9BjVGjn28E58LgSi547JYEpqpgRoo1TErkbyXiRSNDQy ``` ### Withdraw SOL and Call the Solana Program -Make a call to the ZetaChain Gateway to withdraw SOL and call a program on -Solana: - -```bash -npx hardhat zetachain-withdraw-and-call \ - --receiver 9BjVGjn28E58LgSi547JYEpqpgRoo1TErkbyXiRSNDQy \ - --gateway-zeta-chain 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 \ - --zrc20 0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891 \ - --amount 0.01 \ - --network localhost \ - --types '["bytes"]' $(npx ts-node solana/setup/encodeCallArgs.ts "sol" "$USDC_SPL") +``` +PAYLOAD=$(npx zetachain solana encode \ + --connected $PROGRAM_ID \ + --data hello \ + --gateway 94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d) && echo $PAYLOAD ``` -- `--receiver`: The Solana program ID you want to call. -- `--types '["bytes"]'`: Specifies that the contract call argument is a bytes - array (the encoded Solana call data). -- `"$ENCODED_ACCOUNTS_AND_DATA"`: The encoded Solana program call arguments we - generated in the previous step. -- `--zrc20`: ZRC-20 address of SOL on ZetaChain. - -### Withdraw SPL-20 and Call the Solana Program - -Make a call to the ZetaChain Gateway to withdraw ZRC-20 SPL-20 USDC and call a -program on Solana: +Make a call to the ZetaChain Gateway to withdraw SOL and call a program on +Solana: ```bash -npx hardhat zetachain-withdraw-and-call \ +npx zetachain z withdraw-and-call \ + --amount 0.001 \ --receiver 9BjVGjn28E58LgSi547JYEpqpgRoo1TErkbyXiRSNDQy \ - --gateway-zeta-chain 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 \ - --zrc20 0x48f80608B672DC30DC7e3dbBd0343c5F02C738Eb \ - --amount 0.01 \ - --network localhost \ - --types '["bytes"]' $(npx ts-node solana/setup/encodeCallArgs.ts "spl" "$USDC_SPL") + --data $PAYLOAD \ + --private-key $PRIVATE_KEY \ + --rpc http://localhost:8545 \ + --zrc20 0x777915D031d1e8144c90D025C594b3b8Bf07a08d \ + --gateway $GATEWAY_ZETACHAIN ``` - -- `--zrc20`: ZRC-20 address of SPL-20 USDC on ZetaChain. - -In this tutorial you’ve learned how to deploy a universal contract on ZetaChain, -deposit SOL and SPL-20 tokens from Solana, call contracts during deposits, -withdraw assets back to Solana, and even trigger Solana programs upon -withdrawal. From 116c924e04dd1d43866a7aa002817f8f197737a8 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Tue, 19 Aug 2025 17:59:32 +0300 Subject: [PATCH 3/4] switch to devnet --- src/pages/developers/tutorials/solana.mdx | 77 +++++++++-------------- 1 file changed, 31 insertions(+), 46 deletions(-) diff --git a/src/pages/developers/tutorials/solana.mdx b/src/pages/developers/tutorials/solana.mdx index 86b86daeb..6270e765c 100644 --- a/src/pages/developers/tutorials/solana.mdx +++ b/src/pages/developers/tutorials/solana.mdx @@ -3,8 +3,8 @@ deposit SOL and SPL-20 tokens directly from Solana into accounts or smart contracts on ZetaChain. Universal contracts on ZetaChain can handle these deposits and execute contract calls initiated from the Solana blockchain. -- In this tutorial, you'll: -- Set up a local development environment using localnet. +In this tutorial, you'll: + - Deploy a universal contract on ZetaChain. - Deposit tokens (SOL and SPL-20) from Solana to ZetaChain. - Execute deposit-and-call transactions, depositing tokens and calling a @@ -31,36 +31,19 @@ cd call yarn ``` -## Launch Localnet - -This command brings up the local development environment with ZetaChain and -Solana: - -```bash -npx zetachain localnet start --chains solana -``` - -Leave this running in one terminal window. - ## Compile and Deploy an Example Universal Contract -``` -GATEWAY_ZETACHAIN=$(jq -r '.["31337"].contracts[] | select(.contractType == "gateway") | .address' ~/.zetachain/localnet/registry.json) && echo $GATEWAY_ZETACHAIN -``` - -``` -PRIVATE_KEY=$(jq -r '.private_keys[0]' ~/.zetachain/localnet/anvil.json) && echo $PRIVATE_KEY -``` - -``` -MNEMONIC="grape subway rack mean march bubble carry avoid muffin consider thing street" +```bash +GATEWAY_ZETACHAIN=0x6c533f7fe93fae114d0954697069df33c9b74fd7 +ZRC20_SOL=0xADF73ebA3Ebaa7254E859549A44c74eF7cff7501 +RPC_ZETACHAIN=https://zetachain-athens-evm.blockpi.network/v1/rpc/public ``` In a new terminal window, compile and deploy the universal contract: ```bash UNIVERSAL=$(forge create Universal \ - --rpc-url http://localhost:8545 \ + --rpc-url $RPC_ZETACHAIN \ --private-key $PRIVATE_KEY \ --evm-version paris \ --broadcast \ @@ -75,7 +58,7 @@ Deposit SOL tokens from Solana to ZetaChain: ``` npx zetachain solana deposit \ --recipient $UNIVERSAL \ - --mnemonic $MNEMONIC \ + --private-key $PRIVATE_KEY_SOLANA \ --amount 0.01 \ --chain-id 902 ``` @@ -87,8 +70,8 @@ Call the deployed universal contract: ```bash npx zetachain solana call \ --recipient $UNIVERSAL \ - --mnemonic $MNEMONIC \ - --chain-id 902 \ + --private-key $PRIVATE_KEY_SOLANA \ + --chain-id 901 \ --types string \ --values hello ``` @@ -100,9 +83,9 @@ Deposit tokens and simultaneously call the deployed universal contract: ```bash npx zetachain solana deposit-and-call \ --recipient $UNIVERSAL \ - --mnemonic $MNEMONIC \ + --private-key $PRIVATE_KEY_SOLANA \ --amount 0.01 \ - --chain-id 902 \ + --chain-id 901 \ --types string \ --values hello ``` @@ -117,9 +100,9 @@ Withdraw tokens from ZetaChain back to Solana: ```bash npx zetachain z withdraw \ --receiver DrexsvCMH9WWjgnjVbx1iFf3YZcKadupFmxnZLfSyotd \ - --zrc20 0x777915D031d1e8144c90D025C594b3b8Bf07a08d \ + --zrc20 $ZRC20_SOL \ --amount 0.1 \ - --rpc http://localhost:8545 \ + --rpc $RPC_ZETACHAIN \ --gateway $GATEWAY_ZETACHAIN \ --private-key $PRIVATE_KEY ``` @@ -148,33 +131,35 @@ and using the ZetaChain Gateway to perform a "withdraw and call". ### Build and Set Up the Example Solana Program -Set the SPL-20 USDC address. You can find this address in a table in the output -of `localnet`: - ```bash -USDC_SPL=$(jq -r '.["902"].contracts[] | select(.contractType == "userTokenAccountUSDC") | .address' ~/.zetachain/localnet/registry.json) && echo $USDC_SPL +cd solana ``` -```bash -cd solana ``` +anchor build +``` + +If the build fails, run: ``` +rustup update +rm Cargo.lock anchor build ``` +Deploy the program: + ``` -PROGRAM_ID=$(solana program deploy \ - --program-id setup/connected-keypair.json target/deploy/connected.so \ - --url localhost \ - --output json | jq -r .programId) && echo $PROGRAM_ID +PROGRAM_ID=$(solana program deploy target/deploy/connected.so \ + --url devnet \ + --output json| jq -r .programId) && echo $PROGRAM_ID ``` After running this, you should see output indicating that the program was successfully deployed, such as: ``` -Program Id: 9BjVGjn28E58LgSi547JYEpqpgRoo1TErkbyXiRSNDQy +D7FLXZPthgJewjp4jsGBLNSCTdDyhB6GEmWddyqTYLZc ``` ### Withdraw SOL and Call the Solana Program @@ -183,7 +168,7 @@ Program Id: 9BjVGjn28E58LgSi547JYEpqpgRoo1TErkbyXiRSNDQy PAYLOAD=$(npx zetachain solana encode \ --connected $PROGRAM_ID \ --data hello \ - --gateway 94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d) && echo $PAYLOAD + --gateway ZETAjseVjuFsxdRxo6MmTCvqFwb3ZHUx56Co3vCmGis) && echo $PAYLOAD ``` Make a call to the ZetaChain Gateway to withdraw SOL and call a program on @@ -192,10 +177,10 @@ Solana: ```bash npx zetachain z withdraw-and-call \ --amount 0.001 \ - --receiver 9BjVGjn28E58LgSi547JYEpqpgRoo1TErkbyXiRSNDQy \ + --receiver $PROGRAM_ID \ --data $PAYLOAD \ --private-key $PRIVATE_KEY \ - --rpc http://localhost:8545 \ - --zrc20 0x777915D031d1e8144c90D025C594b3b8Bf07a08d \ + --rpc $RPC_ZETACHAIN \ + --zrc20 $ZRC20_SOL \ --gateway $GATEWAY_ZETACHAIN ``` From 09385a61e04e015038632d8b97cefbd18f0158b9 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Mon, 3 Nov 2025 16:15:50 +0300 Subject: [PATCH 4/4] update --- src/pages/developers/tutorials/solana.mdx | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/pages/developers/tutorials/solana.mdx b/src/pages/developers/tutorials/solana.mdx index 6270e765c..266fbc548 100644 --- a/src/pages/developers/tutorials/solana.mdx +++ b/src/pages/developers/tutorials/solana.mdx @@ -147,6 +147,18 @@ rm Cargo.lock anchor build ``` +Generate a new program keypair: + +``` +solana-keygen new -o target/deploy/connected-keypair.json +``` + +Update the program ID in the code: + +``` +anchor keys sync +``` + Deploy the program: ``` @@ -162,10 +174,16 @@ successfully deployed, such as: D7FLXZPthgJewjp4jsGBLNSCTdDyhB6GEmWddyqTYLZc ``` +Initialize the program: + +``` +npx ts-node ./scripts/initialize.ts +``` + ### Withdraw SOL and Call the Solana Program ``` -PAYLOAD=$(npx zetachain solana encode \ +PAYLOAD=$(zetachain solana encode \ --connected $PROGRAM_ID \ --data hello \ --gateway ZETAjseVjuFsxdRxo6MmTCvqFwb3ZHUx56Co3vCmGis) && echo $PAYLOAD @@ -175,7 +193,7 @@ Make a call to the ZetaChain Gateway to withdraw SOL and call a program on Solana: ```bash -npx zetachain z withdraw-and-call \ +zetachain z withdraw-and-call \ --amount 0.001 \ --receiver $PROGRAM_ID \ --data $PAYLOAD \