-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2a8a0a
commit 2203140
Showing
1 changed file
with
73 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,100 @@ | ||
## Foundry | ||
# Cross-Chain Token Transfer | ||
|
||
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** | ||
This repository demonstrates how to deploy and interact with smart contracts for transferring ERC-20 tokens across different blockchains using the Wormhole Protocol. | ||
|
||
Foundry consists of: | ||
## Prerequisites | ||
|
||
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). | ||
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. | ||
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. | ||
- **Chisel**: Fast, utilitarian, and verbose solidity REPL. | ||
Before using this project, make sure you have the following: | ||
|
||
## Documentation | ||
- [Node.js and npm installed](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) | ||
- [Forge](https://book.getfoundry.sh/getting-started/installation) (for compiling and testing smart contracts) | ||
- A funded wallet with testnet tokens for deployment and transfers | ||
|
||
https://book.getfoundry.sh/ | ||
## Getting Started | ||
|
||
## Usage | ||
1. Clone the repository and navigate to the project directory: | ||
|
||
### Build | ||
|
||
```shell | ||
$ forge build | ||
```bash | ||
git clone https://github.com/martin0995/cross-chain-token-transfers | ||
cd cross-chain-token-transfers | ||
``` | ||
|
||
### Test | ||
2. Install the project dependencies: | ||
|
||
```shell | ||
$ forge test | ||
```bash | ||
npm install | ||
``` | ||
|
||
### Format | ||
3. Set up environment variables: | ||
|
||
Create a `.env` file in the root directory and add your `private key`: | ||
|
||
```shell | ||
$ forge fmt | ||
```bash | ||
PRIVATE_KEY=INSERT_PRIVATE_KEY | ||
``` | ||
|
||
### Gas Snapshots | ||
> **_NOTE:_** This private key should be funded with testnet tokens on the chains you want to use. | ||
```shell | ||
$ forge snapshot | ||
``` | ||
4. Configure the chains: | ||
|
||
### Anvil | ||
Edit the `config.js` file to include the chain IDs, contract addresses, and RPC URLs for the chains you want to use. | ||
|
||
```shell | ||
$ anvil | ||
5. Compile the smart contracts: | ||
|
||
```bash | ||
forge compile | ||
``` | ||
|
||
### Deploy | ||
## Deployment | ||
|
||
To deploy the smart contracts: | ||
|
||
```shell | ||
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key> | ||
```bash | ||
npm run deploy | ||
``` | ||
|
||
### Cast | ||
- You will be prompted to select the **`source`** and **`target`** chains for deployment. | ||
- The deployed contract addresses will be saved and updated in `deploy-config/contracts.json`. | ||
|
||
```shell | ||
$ cast <subcommand> | ||
``` | ||
## Token Transfer | ||
|
||
### Help | ||
To initiate a token transfer across chains: | ||
|
||
```shell | ||
$ forge --help | ||
$ anvil --help | ||
$ cast --help | ||
```bash | ||
npm run transfer | ||
``` | ||
|
||
- You will be prompted to select the **`source`** and **`target`** chains for the transfer. | ||
- Provide the token address, recipient address on the target chain, and the amount to transfer. | ||
|
||
## Recommended Test Setup: Transfer USDC | ||
|
||
To test the cross-chain transfer, I recommend using the **USDC token**, as it’s widely supported across different testnets. | ||
|
||
- USDC Token Address on Avalanche Fuji: `0x5425890298aed601595a70ab815c96711a31bc65` | ||
- USDC Token Address on Celo Alfajores: `0x2F25deB3848C207fc8E0c34035B3Ba7fC157602B` | ||
|
||
You can obtain USDC on testnets via the official USDC faucet: | ||
|
||
- [USDC Testnet Faucet](https://faucet.circle.com/) | ||
|
||
Once you have USDC, use the provided addresses above to transfer between testnets. | ||
|
||
## Contracts Overview | ||
|
||
The project includes two main contracts: | ||
|
||
- **`CrossChainSender`** - handles sending tokens from the source chain | ||
- **`CrossChainReceiver`** - handles receiving tokens on the target chain | ||
|
||
## Project Structure | ||
|
||
- **`src/`** - contains the Solidity smart contracts | ||
- **`script/`** - contains TypeScript scripts for deployment and token transfers | ||
- **`deploy-config/`** - configuration files for the chains and deployed contracts | ||
- **`out/`** - contains the compiled contract ABIs and bytecode | ||
|
||
## Notes | ||
|
||
- Ensure your wallet has enough testnet tokens to cover gas fees on both the source and target chains. | ||
- The current setup supports ERC-20 tokens like WETH, USDC, and WBTC. |