Skip to content

Commit

Permalink
Fix Call example on localnet (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev authored Dec 5, 2024
1 parent 513b729 commit e15b128
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 25 deletions.
23 changes: 12 additions & 11 deletions src/pages/developers/tutorials/call.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ With localnet running, open a new terminal window to compile and deploy the
```bash
npx hardhat compile --force
npx hardhat deploy --name Universal --network localhost --gateway 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707
npx hardhat deploy --name Connected --json --network localhost --gateway 0x610178dA211FEF7D417bC0e6FeD39F05609AD788
npx hardhat deploy --name Connected --network localhost --gateway 0x610178dA211FEF7D417bC0e6FeD39F05609AD788
```

You should see output indicating the successful deployment of the contracts:
Expand All @@ -404,12 +404,12 @@ You should see output indicating the successful deployment of the contracts:
πŸ”‘ Using account: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
πŸš€ Successfully deployed "Universal" contract on localhost.
πŸ“œ Contract address: 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB
πŸ“œ Contract address: 0xc351628EB244ec633d5f21fBD6621e1a683B1181
πŸ”‘ Using account: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
πŸš€ Successfully deployed "Conntected" contract on localhost.
πŸ“œ Contract address: 0x9E545E3C0baAB3E08CdfD552C960A1050f373042
πŸš€ Successfully deployed "Connected" contract on localhost.
πŸ“œ Contract address: 0xFD471836031dc5108809D173A067e8486B9047A3
```

**Note**: The deployed contract addresses may differ in your environment.
Expand All @@ -423,8 +423,8 @@ deployment:

```bash
npx hardhat connected-call \
--contract 0x9E545E3C0baAB3E08CdfD552C960A1050f373042 \
--receiver 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB \
--contract 0xFD471836031dc5108809D173A067e8486B9047A3 \
--receiver 0xc351628EB244ec633d5f21fBD6621e1a683B1181 \
--network localhost \
--types '["string"]' alice
```
Expand All @@ -438,8 +438,8 @@ from your deployment:

```bash
npx hardhat universal-call \
--contract 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB \
--receiver 0x9E545E3C0baAB3E08CdfD552C960A1050f373042 \
--contract 0xc351628EB244ec633d5f21fBD6621e1a683B1181 \
--receiver 0xFD471836031dc5108809D173A067e8486B9047A3 \
--zrc20 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe \
--function "hello(string)" \
--network localhost \
Expand All @@ -453,11 +453,12 @@ app, run the following command:

```bash
npx hardhat universal-withdraw-and-call \
--contract 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB \
--receiver 0x9E545E3C0baAB3E08CdfD552C960A1050f373042 \
--zrc20 0x9fd96203f7b22bCF72d9DCb40ff98302376cE09c \
--contract 0xc351628EB244ec633d5f21fBD6621e1a683B1181 \
--receiver 0xFD471836031dc5108809D173A067e8486B9047A3 \
--zrc20 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe \
--function "hello(string)" \
--amount 1 \
--call-options-is-arbitrary-call \
--network localhost \
--types '["string"]' hello
```
Expand Down
44 changes: 37 additions & 7 deletions src/pages/developers/tutorials/swap-any.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,11 @@ Once your environment is set up, compile the contract and deploy it to localnet
using the following command:

```
yarn deploy-any:localnet
npx hardhat deploy \
--name SwapToAnyToken \
--network localhost \
--gateway 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 \
--uniswap-router 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
```

After deployment, you should see an output similar to this:
Expand All @@ -347,7 +351,7 @@ After deployment, you should see an output similar to this:
πŸ”‘ Using account: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
πŸš€ Successfully deployed contract on localhost.
πŸ“œ Contract address: 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB
πŸ“œ Contract address: 0xc351628EB244ec633d5f21fBD6621e1a683B1181
```

## Swap and Withdraw Tokens to Connected Chain
Expand All @@ -356,7 +360,13 @@ To swap tokens from a connected EVM chain and withdraw them to the destination
chain, use the following command:

```
npx hardhat swap-from-evm --network localhost --receiver 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB --amount 1 --target 0x9fd96203f7b22bCF72d9DCb40ff98302376cE09c --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --withdraw true
npx hardhat swap-from-evm \
--network localhost \
--receiver 0xc351628EB244ec633d5f21fBD6621e1a683B1181 \
--amount 1 \
--target 0x05BA149A7bd6dC1F937fA9046A9e05C05f3b18b0 \
--recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
--withdraw true
```

- EVM gateway is called with 1 native gas token (ETH) and a message that
Expand All @@ -376,7 +386,13 @@ If you want to swap tokens and keep them on ZetaChain rather than withdrawing
them, set the `withdraw` flag.

```
npx hardhat swap-from-evm --network localhost --receiver 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB --amount 1 --target 0x9fd96203f7b22bCF72d9DCb40ff98302376cE09c --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --withdraw false
npx hardhat swap-from-evm \
--network localhost \
--receiver 0xc351628EB244ec633d5f21fBD6621e1a683B1181 \
--amount 1 \
--target 0x05BA149A7bd6dC1F937fA9046A9e05C05f3b18b0 \
--recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
--withdraw false
```

In the command above the `withdraw` is `false`, so the target ZRC-20 token will
Expand All @@ -388,7 +404,14 @@ To swap a ZRC-20 token for another ZRC-20 on ZetaChain and withdraw to a
connected chain, run:

```
npx hardhat swap-from-zetachain --network localhost --contract 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB --amount 1 --target 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --zrc20 0x9fd96203f7b22bCF72d9DCb40ff98302376cE09c --withdraw true
npx hardhat swap-from-zetachain \
--network localhost \
--contract 0xc351628EB244ec633d5f21fBD6621e1a683B1181 \
--amount 1 \
--target 0x65a45c57636f9BcCeD4fe193A602008578BcA90b \
--recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
--zrc20 0x05BA149A7bd6dC1F937fA9046A9e05C05f3b18b0 \
--withdraw true
```

## Swap on ZetaChain Without Withdrawing
Expand All @@ -397,7 +420,14 @@ To swap a ZRC-20 token for another ZRC-20 on ZetaChain and transfer it to a
recipient on ZetaChain, run:

```
npx hardhat swap-from-zetachain --network localhost --contract 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB --amount 1 --target 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --zrc20 0x9fd96203f7b22bCF72d9DCb40ff98302376cE09c --withdraw false
npx hardhat swap-from-zetachain \
--network localhost \
--contract 0xc351628EB244ec633d5f21fBD6621e1a683B1181 \
--amount 1 \
--target 0x65a45c57636f9BcCeD4fe193A602008578BcA90b \
--recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
--zrc20 0x05BA149A7bd6dC1F937fA9046A9e05C05f3b18b0 \
--withdraw false
```

## Conclusion
Expand All @@ -413,4 +443,4 @@ on ZetaChain, providing greater flexibility for a variety of use cases.
You can find the source code for this tutorial in the example contracts
repository:

https://github.com/zeta-chain/example-contracts/tree/main/examples/swap]
https://github.com/zeta-chain/example-contracts/tree/main/examples/swap
33 changes: 26 additions & 7 deletions src/pages/developers/tutorials/swap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ their native chain, whether it's an EVM chain or Bitcoin.

```
npx hardhat compile --force
npx hardhat deploy --gateway 0x6c533f7fe93fae114d0954697069df33c9b74fd7 --network zeta_testnet
Β 
npx hardhat deploy \
--gateway 0x6c533f7fe93fae114d0954697069df33c9b74fd7 \
--uniswap-router 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe \
--network zeta_testnet
```

```
Expand All @@ -342,7 +346,7 @@ npx hardhat deploy --gateway 0x6c533f7fe93fae114d0954697069df33c9b74fd7 --networ
## Swap from Base Sepolia to Polygon Amoy

```
npx hardhat evm-deposit-and-call
npx hardhat evm-deposit-and-call \
--receiver 0x162CefCe314726698ac1Ee5895a6c392ba8e20d3 \
--amount 0.001 \
--network base_sepolia \
Expand All @@ -363,7 +367,11 @@ npx hardhat localnet
Compile the contract and deploy it to localnet by running:

```
yarn deploy:localnet
npx hardhat deploy \
--name Swap \
--network localhost \
--gateway 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 \
--uniswap-router 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
```

You should see output similar to:
Expand All @@ -372,15 +380,20 @@ You should see output similar to:
πŸ”‘ Using account: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
πŸš€ Successfully deployed contract on localhost.
πŸ“œ Contract address: 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB
πŸ“œ Contract address: 0xc351628EB244ec633d5f21fBD6621e1a683B1181
```

## Swapping Gas Tokens for ERC-20 Tokens

To swap gas tokens for ERC-20 tokens, run the following command:

```
npx hardhat swap-from-evm --network localhost --receiver 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB --amount 1 --target 0x9fd96203f7b22bCF72d9DCb40ff98302376cE09c --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
npx hardhat swap-from-evm \
--network localhost \
--receiver 0xc351628EB244ec633d5f21fBD6621e1a683B1181 \
--amount 1 \
--target 0x05BA149A7bd6dC1F937fA9046A9e05C05f3b18b0 \
--recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
```

This script deposits tokens into the gateway on a connected EVM chain and sends
Expand Down Expand Up @@ -410,7 +423,13 @@ To swap ERC-20 tokens for gas tokens, adjust the command by specifying the
ERC-20 token you're swapping from using the `--erc20` parameter:

```
npx hardhat swap-from-evm --network localhost --receiver 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB --amount 1 --target 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --erc20 0x0B306BF915C4d645ff596e518fAf3F9669b97016
npx hardhat swap-from-evm \
--network localhost \
--receiver 0xc351628EB244ec633d5f21fBD6621e1a683B1181 \
--amount 1 \
--target 0x05BA149A7bd6dC1F937fA9046A9e05C05f3b18b0 \
--recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
--erc20 0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E
```

Here, the `--erc20` option specifies the ERC-20 token address you're swapping
Expand Down Expand Up @@ -443,4 +462,4 @@ token approvals in cross-chain swaps.
You can find the source code for the tutorial in the example contracts
repository:

[https://github.com/zeta-chain/example-contracts/tree/main/examples/swap](https://github.com/zeta-chain/example-contracts/tree/main/examples/swap)
https://github.com/zeta-chain/example-contracts/tree/main/examples/swap

0 comments on commit e15b128

Please sign in to comment.