ERC-20
How do I transfer ROOT
token?
ROOT token contract address is 0xcCcCCccC00000001000000000000000000000000
and it fully supports the ERC-20 standard.
Copy import { Contract , utils } from "ethers" ;
import { ERC20_PRECOMPILE_ABI } from "@therootnetwork/evm" ;
const ROOT_ADDRESS = "0xcCcCCccC00000001000000000000000000000000" ;
const wallet = new Wallet ( ... );
const contract = new Contract ( ROOT_ADDRESS , ERC20_PRECOMPILE_ABI );
const oneROOT = utils .parseUnits ( 1 , 6 );
// transfer 1 ROOT to Alice
await contract .connect (wallet) .transfer ( "0xE04CC55ebEE1cBCE552f250e85c57B70B2E2625b" , oneROOT);
:::note
ROOT token has 6 decimals and its ID is 1
.
:::
How do I transfer XRP
token or any other ERC-20 tokens?
Just like the ROOT token, XRP and any other ERC-20 token contract addresses can be derived from its native asset IDs.
Copy import { Contract , utils } from "ethers" ;
import { ERC20_PRECOMPILE_ABI , assetIdToERC20Address } from "@therootnetwork/evm" ;
const XRP_ID = 2 ;
const XRP_ADDRESS = assetIdToERC20Address ( 2 );
const wallet = new Wallet ( ... );
const contract = new Contract ( XRP_ADDRESS , ERC20_PRECOMPILE_ABI , wallet);
const oneXRP = utils .parseUnits ( 1 , await contract .decimals ());
// transfer 1 ROOT to Alice
await contract .connect (wallet) .transfer ( "0xE04CC55ebEE1cBCE552f250e85c57B70B2E2625b" , oneXRP);
Tip :
To retrieve a list of available tokens and their asset IDs, check out the Tokens section in our Block Explorer .
ERC-721
How do I create and mint an ERC-721 NFT?
It's possible to create an ERC-712 collection by calling initializeCollection()
method exposed by the nft
precompile .
Copy import { Contract , utils } from "ethers" ;
import { NFT_PRECOMPILE_ABI , NFT_PRECOMPILE_ADDRESS } from "@therootnetwork/evm" ;
const wallet = new Wallet ( ... );
const contract = new Contract ( NFT_PRECOMPILE_ADDRESS , NFT_PRECOMPILE_ABI );
const tx = await contract .connect (wallet) .initializeCollection (
wallet .address , // owner address
utils .toUtf8Bytes ( "My Collection" ) , // collection name
BigNumber .from ( 0 ) , // no max issuance
utils .toUtf8Bytes ( "https://example.com/nft/metadata/" ) , // metadataPath
[ wallet .address] , // royaltyAddresses
[ 100_000 ] , // royaltyEntitlements
);
const receipt = await tx .wait ();
const collectionAddress = ( receipt ?.events as any )[ 0 ]. args .precompileAddress;
Caution :
The royaltyEntitlements
is in permill (parts per million) scaling, so if you want a 10% royalty, that would be 100,000
(as (100_000 / 1_000_000) * 100 = 10%
).
Once the collection is created, use the same owner
wallet to mint the NFT:
Copy import { Contract , utils } from "ethers" ;
import { ERC721_PRECOMPILE_ABI } from "@therootnetwork/evm" ;
const wallet = new Wallet ( ... );
const contract = new Contract (collectionAddress , ERC721_PRECOMPILE_ABI );
// Mint 1 NFT for Alice
await contract .connect (wallet) .mint ( "0xE04CC55ebEE1cBCE552f250e85c57B70B2E2625b" , 1 );