From 2d65ca901c6b5dcfa6bd5382f01587696d0afefb Mon Sep 17 00:00:00 2001 From: Saad Ahmed Siddiqui Date: Thu, 12 Sep 2024 14:37:01 +0200 Subject: [PATCH] resolve comments --- .../evm-to-evm-erc20-contract-call/README.md | 19 +++---------------- .../src/transfer.ts | 16 ++++++++-------- .../src/transfer.ts | 12 ++++++------ 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/examples/evm-to-evm-erc20-contract-call/README.md b/examples/evm-to-evm-erc20-contract-call/README.md index fb66a013a..95f1ce1c6 100644 --- a/examples/evm-to-evm-erc20-contract-call/README.md +++ b/examples/evm-to-evm-erc20-contract-call/README.md @@ -1,6 +1,6 @@ -## Sygma SDK ERC20 Example +## Sygma SDK ERC20 + Contract Call Example -This is an example script that demonstrates the functionality of the SDK using the Sygma ecosystem. The script showcases an ERC20 token transfer between the same account on two different testnets using the Sygma SDK. +This is an example script that demonstrates the functionality of the SDK using the Sygma ecosystem. The script showcases an ERC20 token transfer with a contract call between the same account on two different testnets using the Sygma SDK. ## Prerequisites @@ -57,7 +57,7 @@ Replace between the quotation marks your exported private key: `PRIVATE_KEY="YOUR_PRIVATE_KEY_HERE"` -To send an ERC20 example transfer run: +Run the transfer script using: ```bash yarn run transfer @@ -73,16 +73,3 @@ Replace the placeholder values in the `.env` file with your own Ethereum wallet To replace default rpc Cronos and Sepolia urls use env variables: - `SEPOLIA_RPC_URL="SEPOLIA_RPC_URL_HERE"` - -## Script Functionality - -This example script performs the following steps: - -- initializes the SDK and establishes a connection to the Ethereum provider. -- retrieves the list of supported domains and resources from the SDK configuration. -- Searches for the ERC20 token resource with the specified symbol -- Searches for the Cronos and Sepolia domains in the list of supported domains based on their chain IDs -- Constructs a transfer object that defines the details of the ERC20 token transfer -- Retrieves the fee required for the transfer from the SDK. -- Builds the necessary approval transactions for the transfer and sends them using the Ethereum wallet. The approval transactions are required to authorize the transfer of ERC20 tokens. -- Builds the final transfer transaction and sends it using the Ethereum wallet. diff --git a/examples/evm-to-evm-erc20-contract-call/src/transfer.ts b/examples/evm-to-evm-erc20-contract-call/src/transfer.ts index 79bea4750..d59a595bb 100644 --- a/examples/evm-to-evm-erc20-contract-call/src/transfer.ts +++ b/examples/evm-to-evm-erc20-contract-call/src/transfer.ts @@ -21,15 +21,15 @@ if (!privateKey) { throw new Error("Missing environment variable: PRIVATE_KEY"); } -const SOURCE_CHAIN_ID = 11155111; -const DESTINATION_CHAIN_ID = 84532; +const SEPOLIA_CHAIN_ID = 11155111; +const BASE_SEPOLIA_CHAIN_ID = 84532; const RESOURCE_ID = "0x0000000000000000000000000000000000000000000000000000000000001200"; const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL || "https://ethereum-sepolia-rpc.publicnode.com"; const explorerUrls: Record = { - [SOURCE_CHAIN_ID]: "https://sepolia.etherscan.io", + [SEPOLIA_CHAIN_ID]: "https://sepolia.etherscan.io", }; const getTxExplorerUrl = (params: { txHash: string; @@ -47,21 +47,21 @@ export async function erc20Transfer(): Promise { const config = new Config(); await config.init(process.env.SYGMA_ENV); const resource = config - .getDomainConfig(DESTINATION_CHAIN_ID) + .getDomainConfig(BASE_SEPOLIA_CHAIN_ID) .resources.find((resource) => resource.resourceId === RESOURCE_ID); if (!resource) return; const targetContractAddress = getContractAddress( - DESTINATION_CHAIN_ID, + BASE_SEPOLIA_CHAIN_ID, contract ); const contractInterface = getContractInterface(contract); const params: FungibleTransferParams = { - source: SOURCE_CHAIN_ID, - destination: DESTINATION_CHAIN_ID, + source: SEPOLIA_CHAIN_ID, + destination: BASE_SEPOLIA_CHAIN_ID, sourceNetworkProvider: web3Provider as unknown as Eip1193Provider, resource: RESOURCE_ID, amount: BigInt(1) * BigInt(1e6), @@ -96,7 +96,7 @@ export async function erc20Transfer(): Promise { const response = await wallet.sendTransaction(approval); await response.wait(); console.log( - `Approved, transaction: ${getTxExplorerUrl({ txHash: response.hash, chainId: SOURCE_CHAIN_ID })}` + `Approved, transaction: ${getTxExplorerUrl({ txHash: response.hash, chainId: SEPOLIA_CHAIN_ID })}` ); } diff --git a/examples/evm-to-evm-fungible-transfer/src/transfer.ts b/examples/evm-to-evm-fungible-transfer/src/transfer.ts index 89564fdd5..9ce0b159d 100644 --- a/examples/evm-to-evm-fungible-transfer/src/transfer.ts +++ b/examples/evm-to-evm-fungible-transfer/src/transfer.ts @@ -15,8 +15,8 @@ if (!privateKey) { throw new Error("Missing environment variable: PRIVATE_KEY"); } -const SOURCE_CHAIN_ID = 11155111; -const DESTINATION_CHAIN_ID = 84532; +const SEPOLIA_CHAIN_ID = 11155111; +const BASE_SEPOLIA_CHAIN_ID = 84532; const RESOURCE_ID = "0x0000000000000000000000000000000000000000000000000000000000001200"; const SEPOLIA_RPC_URL = @@ -24,7 +24,7 @@ const SEPOLIA_RPC_URL = "https://eth-sepolia.g.alchemy.com/v2/MeCKDrpxLkGOn4LMlBa3cKy1EzzOzwzG"; const explorerUrls: Record = { - [SOURCE_CHAIN_ID]: "https://sepolia.etherscan.io", + [SEPOLIA_CHAIN_ID]: "https://sepolia.etherscan.io", }; const getTxExplorerUrl = (params: { txHash: string; @@ -39,8 +39,8 @@ export async function erc20Transfer(): Promise { const destinationAddress = await wallet.getAddress(); const params: FungibleTransferParams = { - source: SOURCE_CHAIN_ID, - destination: DESTINATION_CHAIN_ID, + source: SEPOLIA_CHAIN_ID, + destination: BASE_SEPOLIA_CHAIN_ID, sourceNetworkProvider: web3Provider as unknown as Eip1193Provider, resource: RESOURCE_ID, amount: BigInt(1) * BigInt(1e6), @@ -56,7 +56,7 @@ export async function erc20Transfer(): Promise { const response = await wallet.sendTransaction(approval); await response.wait(); console.log( - `Approved, transaction: ${getTxExplorerUrl({ txHash: response.hash, chainId: SOURCE_CHAIN_ID })}` + `Approved, transaction: ${getTxExplorerUrl({ txHash: response.hash, chainId: SEPOLIA_CHAIN_ID })}` ); }