From 5e245e34ab86ea0a8db63db74785670c58edca55 Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 11 Jul 2024 14:47:53 +0800 Subject: [PATCH 1/2] Update api and remix doc --- docs/build/api.md | 39 ++++++++++++++++------------- docs/build/tutorial/foundry-demo.md | 2 ++ docs/build/tutorial/remix-demo.md | 8 +++++- mkdocs.yml | 1 + 4 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 docs/build/tutorial/foundry-demo.md diff --git a/docs/build/api.md b/docs/build/api.md index e94a39a..2b59a17 100644 --- a/docs/build/api.md +++ b/docs/build/api.md @@ -1,39 +1,44 @@ # Msgport API !!! note - If you're looking to explore the workings of the Msgport API more thoroughly, there are [Runnable Examples](https://github.com/msgport/msgport-examples) at your disposal. These practical examples serves as an excellent resource to witness the Msgport API's functionality in real-time. + If you want to delve deeper into the workings of the Msgport API, you can find [Msgport Examples](https://github.com/msgport/msgport-examples) available for your use. These practical examples serve as a great resource to observe the functionality of the Msgport API in real-time. The [Msgport API](https://apidog.msgport.xyz/) serves as a specialized tool to assist Msgport Apps in acquiring additional information necessary for the message delivery process. **Its primary role is to provide an estimation of the cross-chain fee in the native token of the source chain.** This fee covers the various cross-chain expenses that Dapps are responsible for, encapsulating the costs associated with handling token value differences between chains and the delivery and execution fees incurred on both the source and destination chains. By offering the fee estimation in the source chain's native currency, the Msgport API simplifies these complexities, resulting in a seamless user experience. Users benefit from this approach as it eliminates the need for them to possess any tokens from the target chain to facilitate cross-chain transactions. Beyond providing fee information, the API also delivers associated parameter data. These parameters are necessary for the messaging layer, which is the cross-chain messaging protocol employed by Msgport. Simply put, these parameters are the directives required by the messaging protocol's relayer to carry out cross-chain operations on the destination chain. -## Request and Response Example +## Request and Response Click on the [Msgport API](https://apidog.msgport.xyz/) and give it a try. -For request: +Request Example: -![msgport api request](../images/msgport-api-request.png) +![api request](../images/msgport-api-request.png) The request explained below: -* API default url: `https://api.msgport.xyz/v2/fee_with_options` -* Request method: `Post` +* API Default URL: **`https://api.msgport.xyz/v2/fee_with_options`** +* Request Method: `Post` * Params: - * `fromChainId`: The source chain ID. - * `toChainId`: The destination chain ID. - * `fromAddress`: The application address in the source chain. - * `toAddress`: The application address in the destination chain. - * `message`: The eth-abi-encoded function call, which represents the cross-chain message. - * `refundAddress`: The account that receive the potential cross-chain fee refund. -For response: + | Parameter | Description | + | --- | --- | + | `fromChainId` | The source chain ID. | + | `toChainId` | The destination chain ID. | + | `fromAddress` | The application address in the source chain. | + | `toAddress` | The application address in the destination chain. | + | `message` | The eth-abi-encoded function call, which represents the cross-chain message. | + | `refundAddress` | The account that receive the potential cross-chain fee refund. | + +Response Example: ![msgport api response](../images/msgport-api-response.png) The response explained below: -- `code`: Indicates the success of the query. -- `fee`: Represents the estimated fee in the native token of the source chain, utilized when calling the send() method in the source application. -- `params`: Denotes the specific parameters required by the messaging protocol, used as the last parameter in the [`send(uint256 toChainId, address toDapp, bytes calldata message, bytes calldata params)`](./interfaces.md#imessageport) method in the source application. -- `gas`: Reflects the gas cost for the cross-chain message transition. +| Parameter | Description | +| --- | --- | +| `code` | Indicates the success of the query. | +| `fee` | Represents the estimated fee in the native token of the source chain, utilized when calling the send() method in the source application. | +| `params` | Denotes the specific parameters required by the messaging protocol, used as the last parameter in the [`send(uint256 toChainId, address toDapp, bytes calldata message, bytes calldata params)`](./interfaces.md#imessageport) method in the source application.| +| `gas` | Reflects the gas cost for the cross-chain message transition. | diff --git a/docs/build/tutorial/foundry-demo.md b/docs/build/tutorial/foundry-demo.md new file mode 100644 index 0000000..886555d --- /dev/null +++ b/docs/build/tutorial/foundry-demo.md @@ -0,0 +1,2 @@ +# Sending Messages Using Foundry + diff --git a/docs/build/tutorial/remix-demo.md b/docs/build/tutorial/remix-demo.md index 6a3d11a..b6cb76a 100644 --- a/docs/build/tutorial/remix-demo.md +++ b/docs/build/tutorial/remix-demo.md @@ -2,11 +2,17 @@ In this guide, we'll walk you through the process of **sending cross-chain messages from the [Darwinia Koi testnet](https://docs.darwinia.network/build/getting-started/networks/koi/) to the Ethereum Sepolia testnet** using the msgport protocol with [Remix](https://remix.ethereum.org/). No extensive smart contract development expertise is necessary — as long as you're familiar with deploying and interacting with Solidity smart contracts in Remix, you'll be able to follow along. Let's dive in! +## Overview + +This example is based on a basic [Counter](#understand-the-counter-contract) smart contract. The contract is simple and easy to understand. A contract with a `number` storage is deployed in the Sepolia testnet, and another contract named [CounterSender](#prepare-the-countersender-contract) is deployed in the Koi testnet. The goal is to call the `increaseNumber()` function of the Sepolia Counter from the Koi testnet CounterSender. + ## Prerequisites ### Get Koi Test Token -Before we proceed, it's important to understand that in our cross-chain communication, the Koi network serves as the source chain while the Sepolia network acts as the destination chain. It's crucial to have this distinction in mind. According to the msgport design, the fee for sending a cross-chain message is paid using the source chain's native token, which in this case is the Koi testnet token. Therefore, you'll need to acquire some test tokens beforehand. To do so, please use [the provided faucet](https://faucet.triangleplatform.com/darwinia/koi) and ensure you add the Koi network to your Ethereum wallet, such as MetaMask. +Before we proceed, it's important to understand that in our cross-chain communication, the Koi network serves as the source chain while the Sepolia network acts as the destination chain. It's crucial to have this distinction in mind. + +According to the msgport design, the fee for sending a cross-chain message is paid using the source chain's native token, which in this case is the Koi testnet token. Therefore, you'll need to acquire some test tokens beforehand. To do so, please use [the provided faucet](https://faucet.triangleplatform.com/darwinia/koi) and ensure you add the Koi network to your Ethereum wallet, such as MetaMask. ### Understand The Counter Contract diff --git a/mkdocs.yml b/mkdocs.yml index 2891719..111f85b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -192,6 +192,7 @@ nav: - Tutorial: - Sending Messages: - Using Remix: "build/tutorial/remix-demo.md" + - Using Foundry: "build/tutorial/foundry-demo.md" - Validating Messages: "build/tutorial/validation.md" - Explore More Examples: "build/tutorial/examples.md" - Community: From 68d5ac1943fc8ce0e6ca5fb886b832b2a8ea0815 Mon Sep 17 00:00:00 2001 From: bear Date: Thu, 11 Jul 2024 15:08:13 +0800 Subject: [PATCH 2/2] Add foundry demo --- docs/build/tutorial/foundry-demo.md | 145 ++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/docs/build/tutorial/foundry-demo.md b/docs/build/tutorial/foundry-demo.md index 886555d..b4d892f 100644 --- a/docs/build/tutorial/foundry-demo.md +++ b/docs/build/tutorial/foundry-demo.md @@ -1,2 +1,147 @@ # Sending Messages Using Foundry +In the previous section, we have seen how to send messages using Remix. In this section, we will show how to send messages using [Foundry](https://book.getfoundry.sh/). + +## Overview + +This example is based on a basic [Counter](https://github.com/msgport/msgport-examples/blob/main/src/counter/src/Counter.sol) smart contract. The contract is simple and easy to understand. A contract with a `number` storage is deployed in the Sepolia testnet, and another contract named [CounterSender](https://github.com/msgport/msgport-examples/blob/main/src/counter/src/CounterSender.sol) is deployed in the [Koi testnet](https://docs.darwinia.network/build/getting-started/networks/koi/). The goal is to call the `increaseNumber()` function of the Sepolia Counter from the Koi testnet CounterSender. + +## Preparation + +### Clone repo and submodules + +```bash +git clone --recursive https://github.com/msgport/msgport-examples.git +cd msgport-examples +``` + +### Account with balance + +Before proceeding with the tutorial, you need an account with sufficient balance. This is required to perform contract operations in both the [Koi](https://docs.darwinia.network/build/getting-started/networks/koi/) and Sepolia testnets. If you don't have an account with sufficient balance, you may encounter difficulties when interacting with these contracts. Once you have the account, copy and create a `.env` file based on the `.env.example` file in the root of the repository. This will allow you to continue with the tutorial. + +### Deploy Counter in the Sepolia testnet + +Running the script to deploy the `Counter` contract in the Sepolia testnet: + +```bash +forge script src/counter/script/Deploy.s.sol:DCounter --broadcast --rpc-url https://ethereum-sepolia.publicnode.com +``` + +The output: + +```bash +Script ran successfully. +== Logs == + Counter has been deployed at chain: 11155111, contract: 0xc2fEFb4FDC7E6CaB6FaC7cb3A83902Aea0cB0348 + +## Setting up 1 EVM. + +========================== + +Chain 11155111 +Estimated gas price: 0.055286148 gwei +Estimated total gas used for script: 214358 +Estimated amount required: 0.000011851028112984 ETH +========================== +##### sepolia +✅ [Success]Hash: 0xe866afcca912979c531b5100876c3e86315d9a641dcf232c5c95b702e220fe51 +Contract Address: 0xc2fEFb4FDC7E6CaB6FaC7cb3A83902Aea0cB0348 +Block: 6138758 +Paid: 0.00000868981192167 ETH (164935 gas * 0.052686282 gwei) +✅ Sequence #1 on sepolia | Total Paid: 0.00000868981192167 ETH (164935 gas * avg 0.052686282 gwei) +``` + +### Check the initial number value + +Once the `Counter` has been deployed, we can check the current `number` stored in the Counter. + +```bash +forge script src/counter/script/GetNumber.s.sol:GetNumber --rpc-url https://ethereum-sepolia.publicnode.com +``` + +The output: + +```bash +The current number stored in the Counter is: 0 +``` + +### Deploy CounterSender in the Koi testnet + +Running the script to deploy the `CounterSender` contract in the Koi testnet: + +```bash +forge script src/counter/script/Deploy.s.sol:DCounterSender --broadcast --rpc-url https://koi-rpc.darwinia.network +``` + +The output: + +```bash +[⠊] Compiling... +[⠔] Compiling 28 files with Solc 0.8.21 +[⠒] Solc 0.8.21 finished in 3.40s +Compiler run successful with +Script ran successfully. +== Logs == + Sender has been deployed at chain: 701, contract: 0x36d95D59391e202b44B37d5599a119C1b718efB1 + +## Setting up 1 EVM. +========================== +Chain 701 + +Estimated gas price: 150.706512128 gwei +Estimated total gas used for script: 272867 +Estimated amount required: 0.041122833844830976 ETH +========================== +##### 701 +✅ [Success]Hash: 0xb3985ea1d6b8d9795d829684ef3a0f098e8eab8a45f2d5f65e1256d2e3818e1e +Contract Address: 0x36d95D59391e202b44B37d5599a119C1b718efB1 +Block: 97100 +Paid: 0.015820717523661056 ETH (209954 gas * 75.353256064 gwei) +``` +### Send Message from the Koi testnet to the Sepolia testnet + +```bash +forge script src/counter/script/IncreaseNumber.s.sol:IncreaseNumber -vv --broadcast --rpc-url https://koi-rpc.darwinia.network --gas-estimate-multiplier 200 +``` + +The output: + +```bash +Script ran successfully. + +== Logs == + the body is: {"fromAddress":"0x36d95D59391e202b44B37d5599a119C1b718efB1","fromChainId":701,"message":"0x5b4ef819","ormp":{"refundAddress":"0x0000000000000000000000000000000000000000"},"toAddress":"0xea02E187B97622Ca74c58107236b0182CE727b70","toChainId":11155111} + The message has been sent to chain: 11155111, msgId: 0xec7358b1570f5b23dee8a732ece84970e8ab9c349f610440a38c07a5fcd3a772 + +## Setting up 1 EVM. +========================== +Chain 701 +Estimated gas price: 150.706512128 wei +Estimated total gas used for script: 264208 +Estimated amount required: 0.039817866156314624 ETH + +========================== + +##### 701 +✅ [Success]Hash: 0x5a9c8e8150391fd0eee27b8f78128d07fb6c806cc12ff60c220c586daef20a1e +Block: 97272 +Paid: 0.013607441686549248 ETH (180582 gas * 75.353256064 gwei) + +✅ Sequence #1 on 701 | Total Paid: 0.013607441686549248 ETH (180582 gas * avg 75.353256064 gwei) +``` + +After submitting the transaction, you have successfully sent a message from the Koi testnet to the Sepolia testnet. Please wait for the message to be delivered and dispatched in the Sepolia testnet. + +The msgId `0xec7358b1570f5b23dee8a732ece84970e8ab9c349f610440a38c07a5fcd3a772` is the unique identifier of the message, you can track the message status in the [Msgport Scan](https://scan.msgport.xyz/). It usually takes less than 5 minutes. Once the message status turns from `Inflight` to `Success`, you can check the `number` value again in the Sepolia testnet. + +### Check the number again + +```bash +forge script src/counter/script/GetNumber.s.sol:GetNumber --rpc-url https://ethereum-sepolia.publicnode.com +``` + +The output: + +```bash +The current number stored in the Counter is: 1 +``` \ No newline at end of file