You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 11, 2025. It is now read-only.
#EVM-to-EVM (Sepolia to Base Sepolia) token transfer example
2
2
3
-
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.
3
+
In the following example, we will use the `TESTNET` environment to perform a cross-chain ERC-20 transfer with 1 testnet `USDC` tokens. The transfer will be initiated on the EVM-side via the Ethereum Sepolia testnet and received on Base Sepolia testnet.
4
4
5
-
## Prerequisites
5
+
This is an example script that demonstrates the functionality of the Sygma SDK and the wider Sygma ecosystem of relayers and bridge and handler contracts. The complete example can be found in this [repo](https://github.com/sygmaprotocol/sygma-sdk/tree/main/examples/evm-to-evm-fungible-transfer).
6
+
7
+
### Prerequisites
6
8
7
9
Before running the script, ensure that you have the following:
8
10
9
-
- Node.js
11
+
- Node.js v18
10
12
- Yarn (version 3.4.1 or higher)
11
-
- A development wallet funded with `ERC20LRTest` tokens from the [Sygma faucet](https://faucet-ui-stage.buildwithsygma.com/)
12
13
- The [exported private key](https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key) of your development wallet
13
-
-[Sepolia ETH](https://www.alchemy.com/faucets/ethereum-sepolia) for gas
14
+
-Testnet [ETH](https://cloud.google.com/application/web3/faucet/ethereum/sepolia) for gas
14
15
- An Ethereum [provider](https://www.infura.io/) (in case the hardcoded RPC within the script does not work)
16
+
- A development wallet funded with `USDC` tokens from the [USDC Faucet](https://faucet.circle.com)
17
+
18
+
:::danger
19
+
We make use of the dotenv module to manage exported private keys with environment variables. Please note that accidentally committing a .env file containing private keys to a wallet with real funds, onto GitHub, could result in the complete loss of your funds. **Never expose your private keys.**
20
+
:::
15
21
16
-
## Getting started
22
+
###Getting started
17
23
18
-
### 1. Clone the repository
24
+
1. Clone the repository
19
25
20
-
To get started, clone this repository to your local machine with:
26
+
Clone the sygma-sdk repository into a directory of your choice, and then `cd` into the folder:
To start the example you need to build the sdk first with:
43
+
Build the SDK by running the following command:
38
44
39
45
```bash
40
-
yarn build:all
46
+
yarn build
41
47
```
42
48
43
-
##Usage
49
+
4. Usage
44
50
45
51
This example uses the `dotenv` module to manage private keys. To run the example, you will need to configure your environment variable to include your test development account's [exported private key](https://support.metamask.io/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key). A `.env.sample` is provided as a template.
46
52
@@ -55,34 +61,131 @@ touch .env
55
61
56
62
Replace between the quotation marks your exported private key:
57
63
58
-
`PRIVATE_KEY="YOUR_PRIVATE_KEY_HERE"`
64
+
```dotenv
65
+
PRIVATE_KEY="YOUR_PRIVATE_KEY_HERE"
66
+
```
59
67
60
-
To send an ERC20 example transfer run:
68
+
To send an ERC-20 example transfer from EVM to EVM, run:
61
69
62
70
```bash
71
+
cd examples/evm-to-evm-fungible-transfer
63
72
yarn run transfer
64
73
```
65
74
66
-
The example will use `ethers` in conjuction with the sygma-sdk to
67
-
create a transfer from `Sepolia` to `Holesky` with a test ERC20 token.
75
+
The example will use `ethers` in conjunction with the sygma-sdk to create a transfer from Sepolia to Base Sepolia with the `USDC` token. It will be received on Sepolia as the `USDC` token.
76
+
77
+
## Script functionality
78
+
79
+
This example script performs a cross-chain ERC-20 token transfer using the Sygma SDK. The transfer starts on one EVM chain (e.g., Sepolia) and is received on another EVM chain (e.g., BASE). Here’s how the script works:
80
+
81
+
### 1. Imports the Required Packages:
82
+
83
+
The script first imports all the necessary modules, including those from the Sygma SDK (for asset transfer) and ethers.js (for interacting with Ethereum wallets and providers).
The script loads environment variables using the dotenv module. This includes sensitive information like your private key, which should be stored in a .env file for security purposes.
68
110
69
-
Replace the placeholder values in the `.env` file with your own Ethereum wallet private key.
111
+
```ts
112
+
importdotenvfrom"dotenv";
70
113
71
-
**Note**
114
+
dotenv.config();
72
115
73
-
To replace default rpc Cronos and Sepolia urls use env variables:
The PRIVATE_KEY environment variable is critical for signing transactions with your Ethereum wallet.
124
+
125
+
### 3. Defines the Transfer Function:
76
126
77
-
## Script Functionality
127
+
The erc20Transfer function is the main function that handles the token transfer. It initializes the provider and wallet, sets up the asset transfer, and constructs the transfer object.
- initializes the SDK and establishes a connection to the Ethereum provider.
82
-
- retrieves the list of supported domains and resources from the SDK configuration.
83
-
- Searches for the ERC20 token resource with the specified symbol
84
-
- Searches for the Cronos and Sepolia domains in the list of supported domains based on their chain IDs
85
-
- Constructs a transfer object that defines the details of the ERC20 token transfer
86
-
- Retrieves the fee required for the transfer from the SDK.
87
-
- 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.
88
-
- Builds the final transfer transaction and sends it using the Ethereum wallet.
135
+
The script sets up a Web3 provider and creates a wallet using the provided private key. In this case, the script is interacting with the Sepolia network.
The Sygma SDK’s EVM Asset Transfer object is initialized using the TESTNET environment. This object is used to build and manage the cross-chain ERC-20 transfer. The script constructs a transfer object using the sender’s address, recipient’s address (same in this case but on a different chain), and the amount to be transferred (1 token, represented with 6 decimal places).
const transfer =awaitcreateFungibleAssetTransfer(params);
161
+
```
162
+
163
+
### 6. Builds and Sends Approval Transactions:
164
+
165
+
Before the actual transfer, approval transactions must be sent to authorize the transfer of ERC-20 tokens. The script iterates over the approval transactions, sends them, and logs their transaction hashes.
### 7. Builds and Sends the Final Transfer Transaction:
176
+
177
+
After approval, the script builds the transfer transaction and sends it to the Ethereum network. Once the transaction is sent, it logs the transaction hash.
0 commit comments