Important variables:
MaGGA_BLOCKCHAIN_ID = 0x02f8b60b4d4070cf62e67802fe6532d4fcfc6582b4048d040ed6cfc7247d86d8
MaGGA_RPC = "https://subnets.avax.network/gaming/testnet/rpc"
FUJI_C_BLOCKCHAIN_ID = 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
FUJI_RPC = "https://api.avax-test.network/ext/bc/C/rpc"
- Set up privat the privat key of your crypto wallet and save it as an environmental variable:
export PK=YOUR_PRIVATE_KEY
- Deploy Sender Contract on C chain
forge create --rpc-url fuji-c --private-key $PK contracts/MaGGA/senderMaGGA.sol:SenderOnCChain
The output should look like this:
[⠊] Compiling...
[⠢] Compiling 2 files with Solc 0.8.18
[⠆] Solc 0.8.18 finished in 158.51ms
Compiler run successful!
Deployer: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
Deployed to: 0xAAASENDER_CONTRACT_ADDRESS888
Transaction hash: 0x48a1ffaa8aa8011f842147a908ff35a1ebfb75a5a07eb37ae96a4cc8d7feafd7
-
If you are using Avacloud, authorize the Sender Contract on your L1 Blockchain.
-
Save the adress where the smart constract was deployed to:
export SENDER_CONTRACT_ADDRESS=0xAAASENDER_CONTRACT_ADDRESS888
- Deploy Receiver Contract on MaGGA chain:
forge create --rpc-url MaGGA --private-key $PK contracts/MaGGA/receiverMaGGA.sol:ReceiverOnSubnet
The output should look like this:
[⠊] Compiling...
[⠒] Compiling 2 files with Solc 0.8.18
[⠢] Solc 0.8.18 finished in 81.53ms
Compiler run successful!
Deployer: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
Deployed to: 0xYYYRECEIVER_CONTRACT_ADDRESS444
Transaction hash: 0xcde7873e9e3c68fb00a2ad6644dceb64a01a41941da46de5a0f559d6d70a1638
-
If you are using Avacloud, authorize the Sender Contract on your L1 Blockchain.
-
Save the adress where the smart constract was deployed to, executing the :
export RECEIVER_CONTRACT_ADDRESS=0xYYYRECEIVER_CONTRACT_ADDRESS444
- Send Transaction from C-Chain to MaGGA L1 Chain:
cast send --rpc-url MaGGA --private-key $PK $SENDER_CONTRACT_ADDRESS "sendMessage(address,string)" $RECEIVER_CONTRACT_ADDRESS "Hello MaGGA!"
- Read variable on MaGGA L1 Chain to make sure, that the right message was received:
cast call --rpc-url MaGGA $RECEIVER_CONTRACT_ADDRESS "lastMessage()(string)"
- If you do not have already set up a privat key, please refer to Step 1 of "Create simple interchain messaging between Fuji C-Chain and MaGGA L1 Chain":
export PK=YOUR_PRIVATE_KEY
- Deploy the token creation contract on Fuji C-chain:
forge create --rpc-url fuji-c --private-key $PK contracts/MaGGA/createToken.sol:MyToken
The output should look like this:
[⠊] Compiling...
[⠢] Compiling 2 files with Solc 0.8.18
[⠆] Solc 0.8.18 finished in 158.51ms
Compiler run successful!
Deployer: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
Deployed to: 0xAAATOKEN_CREATION_CONTRACT_ADDRESS888
Transaction hash: 0x48a1ffaa8aa8011f842147a908ff35a1ebfb75a5a07eb37ae96a4cc8d7feafd7
-
If you are using Avacloud, authorize the token creation smart contract (i.e. 0xAAATOKEN_CREATION_CONTRACT_ADDRESS888) on your L1 Blockchain.
-
Save the adress where the token creation smart contract was deployed to as an environmental variable:
export TOKEN_CREATION_CONTRACT_ADDRESS=0xAAATOKEN_CREATION_CONTRACT_ADDRESS888
- Deploy Sender Contract on C chain
forge create --rpc-url fuji-c --private-key $PK contracts/MaGGA/sendAmount.sol:SendAmountOnCChain
The output should look like this:
[⠊] Compiling...
[⠢] Compiling 2 files with Solc 0.8.18
[⠆] Solc 0.8.18 finished in 158.51ms
Compiler run successful!
Deployer: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
Deployed to: 0xAAASENDER_CONTRACT_ADDRESS888
Transaction hash: 0x48a1ffaa8aa8011f842147a908ff35a1ebfb75a5a07eb37ae96a4cc8d7feafd7
-
If you are using Avacloud, authorize the sender smart contract (i.e. 0xAAASENDER_CONTRACT_ADDRESS888) on your L1 Blockchain.
-
Save the adress where the sender smart contract was deployed to as an environmental variable:
export SENDER_CONTRACT_ADDRESS=0xAAASENDER_CONTRACT_ADDRESS888
- Deploy Receiver Contract on MaGGA chain:
forge create --rpc-url MaGGA --private-key $PK contracts/MaGGA/receiveMaGGATokens.sol:ReceiveMaGGATokens
The output should look like this:
[⠊] Compiling...
[⠒] Compiling 2 files with Solc 0.8.18
[⠢] Solc 0.8.18 finished in 81.53ms
Compiler run successful!
Deployer: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
Deployed to: 0xYYYRECEIVER_CONTRACT_ADDRESS444
Transaction hash: 0xcde7873e9e3c68fb00a2ad6644dceb64a01a41941da46de5a0f559d6d70a1638
-
If you are using Avacloud, authorize the Receiver Contract (i.e. 0xYYYRECEIVER_CONTRACT_ADDRESS444) on your L1 Blockchain.
-
Save the adress where the receiver smart constract was deployed to as an environmental varaible:
export RECEIVER_CONTRACT_ADDRESS=0xYYYRECEIVER_CONTRACT_ADDRESS444
- Send Transaction from C-Chain to MaGGA L1 Chain:
cast send --rpc-url MaGGA --private-key $PK $SENDER_CONTRACT_ADDRESS "sendAmount(address,uint)" $RECEIVER_CONTRACT_ADDRESS 100
- Read variable on MaGGA L1 Chain to make sure, that the right message was received:
cast call --rpc-url MaGGA $RECEIVER_CONTRACT_ADDRESS "lastAmount()(uint)"
This starter kit will get you started with developing solidity smart contract dApps on the C-Chain or on an Avalanche L1. It provides all tools to build cross-L1 dApps using Teleporter. It includes:
- Avalanche CLI: Run a local Avalanche Network
- Foundry:
- Forge: Compile and Deploy smart contracts to the local network, Fuji Testnet or Mainnet
- Cast: Interact with these smart contracts
- Teleporter: All contracts you may want to interact with Teleporter
- AWM Relayer: The binary to run your own relayer
- Examples: Contracts showcasing how to achieve common patterns, such as sending simple messages, call functions of a contract on another blockchain and bridging assets. Please note that these example contracts have not been audited and are for educational purposes only
- BuilderKit: A component library providing UI elements for ICTT bridges, Cross-Chain swaps, ...
This starter kit utilizes a Dev Container specification. Dev Containers use containerization to create consistent and isolated development environments. All of the above mentioned components are pre-installed in that container. These containers can be run using GitHub Codespaces or locally using Docker and VS Code. You can switch back and forth between the two options.
You can run them directly on Github by clicking Code, switching to the Codespaces tab and clicking Create codespace on main. A new window will open that loads the codespace. Afterwards you will see a browser version of VS code with all the dependencies installed. Codespace time out after some time of inactivity, but can be restarted.
Alternatively, you can run them locally. You need docker installed and VS Code with the extensions Dev Container extension. Then clone the repository and open it in VS Code. VS Code will ask you if you want to reopen the project in a container.
To start a local Avalanche network with your own teleporter-enabled L1 inside the container follow these commands. Your Avalanche network will be completely independent of the Avalanche Mainnet and Fuji Testnet. It will have its own Primary Network (C-Chain, X-Chain & P-Chain). You will not have access to services available on Fuji (such as Chainlink services or bridges). If you require these, go to the Fuji Testnet section.
First let's create out L1 configuration. Follow the dialog and if you don't have special requirements for precompiles just follow the suggested options. For the Airdrop of the native token select "Airdrop 1 million tokens to the default ewoq address (do not use in production)". Keep the name "mysubnet" to avoid additional configuration.
avalanche blockchain create myblockchain
Now let's spin up the local Avalanche network and deploy our L1. This will also deploy the Teleporter messenger and the registry on our L1 and the C-Chain.
avalanche blockchain deploy myblockchain
Make sure to add the RPC Url to the foundry.toml
file if you have chosen a different name than myblockchain
. If you've used myblockchain
the rpc is already configured.
[rpc_endpoints]
local-c = "http://localhost:9650/ext/bc/C/rpc"
myblockchain = "http://localhost:9650/ext/bc/myblockchain/rpc"
anotherblockchain = "http://localhost:9650/ext/bc/BASE58_BLOCKCHAIN_ID/rpc"