Utilizing test tokens in dev environment
Introduction
The Cartesi CLI is one of the most important tools for developing applications with Cartesi. It provides a wide range of functionalities that simplify and automate the process of setting up, deploying, and interacting with your applications.
When you run your application using the cartesi run command, the CLI automatically spins up a Local anvil network in a Docker container. Within this network, all the required contracts are deployed such as the InputBox contract, your application contract, and Portals contract.
In addition, the CLI also deploys test token contracts by default:
- ERC20 (
TestToken) - ERC721 (
TestNFT) - ERC1155 (
TestMultiToken)
These contracts are owned by the Anvil's first wallet address. This ensures developers have immediate access to and ownership over these tokens for testing purposes, without the need for manual deployments. More details about the different addresses provided by anvil can be found on the Anvil official Docs.
This tutorial will guide you through using these default tokens effectively while developing in a local devnet environment.
Tokens basic Information
The following table lists the default test tokens deployed by the CLI:
| Token | keyword | Value |
|---|---|---|
| ERC20 Token | Token Name | TestToken |
| Token Symbol | TEST | |
| Token Decimal | 18 | |
| Token Address | 0xFBdB734EF6a23aD76863CbA6f10d0C5CBBD8342C | |
| Contract Owner | 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 | |
| ERC721 Token | Token Name | TestNFT |
| Token Symbol | SUNN | |
| Token Address | 0xBa46623aD94AB45850c4ecbA9555D26328917c3B | |
| Contract Owner | 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 | |
| ERC1155 Token | Token Name | TestMultiToken |
| Token Address | 0xDC6d64971B77a47fB3E3c6c409D4A05468C398D2 | |
| Contract Owner | 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 |
You can also view these token addresses at any time using the CLI command:
cartesi address-book
ERC20 Test Token
The ERC20 TestToken is based on the OpenZeppelin ERC20 implementation. It is deployed alongside your application contracts on the anvil devnet, with ownership assigned to the default anvil wallet 0xFBdB734EF6a23aD76863CbA6f10d0C5CBBD8342C, ensuring that developers can readily access these test tokens without needing to manually deploy or transfer new token contracts. However, you can transfer these tokens to other wallets and also to your applications for the duration of which your anvil network is active as these transactions reset every time you restart your anvil devnet, or stop your application using the Cartesi CLI.
Minting ERC20 Test Tokens
Minting new tokens on the TestToken is currently disabled, but at deployment 1000000000 * 10 units of the token was minted to the default anvil wallet 0xFBdB734EF6a23aD76863CbA6f10d0C5CBBD8342C, this amount should be more than suitable for testing your application. With that covered, we can proceed to transferring and also depositing these tokens to your application.
Transferring the ERC20 Test Token to other wallets
When testing interactions that require multiple addresses (e.g., deposits from different users), you may need to transfer tokens from the owner account to other wallets. For this example, we’ll use the second Anvil address as the recipient. You can change the recipient to any address of your choice.
Using Cast Command
- Structure
- Sample
cast send <testTokenContract address> "transfer(address,uint256)" <receivers address> <token amount> --rpc-url <rpc_url> --private-key <private key>
cast send 0xFBdB734EF6a23aD76863CbA6f10d0C5CBBD8342C "transfer(address,uint256)" 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 202 --rpc-url http://127.0.0.1:6751/anvil --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
The above command calls the transfer(address,uint256) in the testToken contract 0xFBdB7...8342C. The command passes the following argument to the function: receivers address= 0x709979...c79C8and amount= 202. While you can always change the amount argument to match what you intend to deposit to your application, it's important to always maintain the same testToken contract as well as the private-key 0xac0974b...f2ff80.