Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
saadahmsiddiqui committed Sep 12, 2024
1 parent 237e631 commit 2d65ca9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
19 changes: 3 additions & 16 deletions examples/evm-to-evm-erc20-contract-call/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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.
16 changes: 8 additions & 8 deletions examples/evm-to-evm-erc20-contract-call/src/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, string> = {
[SOURCE_CHAIN_ID]: "https://sepolia.etherscan.io",
[SEPOLIA_CHAIN_ID]: "https://sepolia.etherscan.io",
};
const getTxExplorerUrl = (params: {
txHash: string;
Expand All @@ -47,21 +47,21 @@ export async function erc20Transfer(): Promise<void> {
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),
Expand Down Expand Up @@ -96,7 +96,7 @@ export async function erc20Transfer(): Promise<void> {
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 })}`
);
}

Expand Down
12 changes: 6 additions & 6 deletions examples/evm-to-evm-fungible-transfer/src/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ 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://eth-sepolia.g.alchemy.com/v2/MeCKDrpxLkGOn4LMlBa3cKy1EzzOzwzG";

const explorerUrls: Record<number, string> = {
[SOURCE_CHAIN_ID]: "https://sepolia.etherscan.io",
[SEPOLIA_CHAIN_ID]: "https://sepolia.etherscan.io",
};
const getTxExplorerUrl = (params: {
txHash: string;
Expand All @@ -39,8 +39,8 @@ export async function erc20Transfer(): Promise<void> {
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),
Expand All @@ -56,7 +56,7 @@ export async function erc20Transfer(): Promise<void> {
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 })}`
);
}

Expand Down

0 comments on commit 2d65ca9

Please sign in to comment.