Create ERC20 tokens
Only issuer accounts can generate assets. If you don't have an issuer, follow the instructions on how to create an Issuer account in the previous section.
Create ERC20 token
Make a POST call to {{CODEFI_API}}/essentials/token/fungible?userId={{issuer}}
with the following body:
{
"tokenStandard": "ERC20Token",
"symbol": "{{tokenSymbol}}",
"name": "{{tokenName}}",
"data": {
"[OPTIONAL]": "[OPTIONAL] Additional use case specific data"
}
}
Authenticate the call with the admin access token.
The created token ID can be found in the response .token.id
.
ERC20TOKEN_ID=$(curl \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ADMIN_ACCESS_TOKEN" \
--request POST \
--data '{ "tokenStandard": "ERC20Token", "symbol": "TST1", "name": "Test ERC20 Token", "data": {} }' \
$CODEFI_API/essentials/token/fungible?userId=$ISSUER_ID | jq -r '.token.id')
echo ERC20TOKEN_ID=$ERC20TOKEN_ID
ERC20TOKEN_ID=02fd5e9b-90af-43d7-b069-9472a3ead00c
Mint ERC20 token
Make a POST call to {{CODEFI_API}}/essentials/token/fungible/{{token}}/transaction/mint?userId={{issuerId}}
with the following body:
{
"recipientId": "{{investorId1}}",
"quantity": "1000",
"price": "10",
"data": {
"[OPTIONAL]": "[OPTIONAL] Additional use case specific data"
}
}
curl\
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ADMIN_ACCESS_TOKEN" \
--request POST --data '{ "recipientId": "'"$INVESTOR1_ID"'", "quantity": "1000", "price": "10", "data": {} }' \
$CODEFI_API/essentials/token/fungible/$ERC20TOKEN_ID/transaction/mint?userId=$ISSUER_ID
Wait for the transaction validation on the blockchain.
{
...
"message": "Minting of 1000 fungible token(s), for investor ed3517df-c9ac-4952-bc53-8ff88457b39c, has been successfully requested (transaction sent)"
}
Transfer ERC20 tokens
Make a POST call to {{CODEFI_API}}/essentials/token/fungible/{{tokenId}}/transaction/transfer?userId={{investorId1}}
with the following body:
{
"recipientId": "{{recipient}}",
"quantity": "400",
"data": {
"[OPTIONAL]": "[OPTIONAL] Additional use case specific data"
}
}
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ADMIN_ACCESS_TOKEN" \
--request POST \
--data '{ "recipientId": "'"$INVESTOR2_ID"'", "quantity": "400", "data": {} }' \
$CODEFI_API/essentials/token/fungible/$ERC20TOKEN_ID/transaction/transfer?userId=$INVESTOR1_ID
Wait for the transaction validation on the blockchain.
{
...
"message": "Transfer of 400 fungible token(s), from investor ed3517df-c9ac-4952-bc53-8ff88457b39c, to investor 72f44a8f-3ded-462d-88a4-b45833e95ea0, has been successfully requested (transaction sent)"
}
Burn ERC20 tokens
Make a POST call to {{CODEFI_API}}/essentials/token/fungible/{{token}}/transaction/burn?userId={{investorId1}}
with the following body:
{
"quantity": "50",
"data": {
"[OPTIONAL]": "[OPTIONAL] Additional use case specific data"
}
}
Wait for the transaction validation on the blockchain.
curl \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ADMIN_ACCESS_TOKEN" \
--request POST --data '{ "quantity": "50", "data": {} }' \
$CODEFI_API/essentials/token/fungible/$ERC20TOKEN_ID/transaction/burn?userId=$INVESTOR2_ID
{
...
"message": "Burn of 50 fungible token(s), from investor 72f44a8f-3ded-462d-88a4-b45833e95ea0, has been successfully requested (transaction sent)"
}
Check ERC20 balances
Make a GET call to {{CODEFI_API}}/essentials/token/{{token}}/investor?withVehicles=true&withBalances=true&offset=0&limit=10&userId={{issuerId}}
.
curl \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ADMIN_ACCESS_TOKEN" \
--request GET \
$CODEFI_API/essentials/token/$ERC20TOKEN_ID/investor?withVehicles=true\&withBalances=true\&offset=0\&limit=10\&userId=$ISSUER_ID
{
"users": [
{
"id": "72f44a8f-3ded-462d-88a4-b45833e95ea0", // {{ INVESTOR2_ID }}
...
"userType": "INVESTOR",
...
"email": "[email protected]",
...
"firstName": "Dan",
"lastName": "Investor",
"defaultWallet": "0x92309970707617000a80F4d4621aCb47DC2302Dd",
"tokenRelatedData": {
...
"balances": {
"total": 350
}
}
},
{
"id": "ed3517df-c9ac-4952-bc53-8ff88457b39c", // {{ INVESTOR2_ID }}
...
"userType": "INVESTOR",
...
"email": "[email protected]",
...
"firstName": "Carol",
"lastName": "Investor",
"defaultWallet": "0x2DFB0F691Eb6a2EA437eFbcc53580494308998Ff",
...
"tokenRelatedData": {
...
"balances": {
"total": 600
}
}
}
],
"count": 2,
"total": 2,
"message": "2 user(s) listed successfully"
}