Skip to content

Managing ERC20 Tokens with FSCO Asset Service

Summary

This guide will walk you through the process of managing ERC20 tokens using the FSCO Asset Service. By the end of this guide, you will have:

  • Minted new ERC20 tokens
  • Transferred tokens between addresses
  • Approved token spending
  • Checked token balances
  • Burned tokens

Prerequisites

  • An FSCO account with API access
  • A registered ERC20 contract deployment (see Registering a Contract guide)
  • A wallet to interact with (see Creating a Wallet guide)
  • Environment variables set for your contract deployment ID (CONTRACT_DEPLOYMENT_ID) and wallet ID (WALLET_ID)

Minting ERC20 Tokens

To mint new ERC20 tokens, we’ll use the io.fsco.asset.command.erc20.mint operation. This will create new tokens and assign them to a specified recipient.

import axios from 'axios';
const mintResponse = await axios.post('https://staging.api.fsco.io/v2/asset/erc20/mint', {
recipient: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
amount: '1000000000000000000', // 1 token with 18 decimals
contractDeploymentId: process.env.CONTRACT_DEPLOYMENT_ID
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.TOKEN}`
}
});
const mintTxId = mintResponse.data.queryId;
console.log('Tokens minted successfully. Transaction ID:', mintTxId);

Transferring ERC20 Tokens

To transfer ERC20 tokens between addresses, use the io.fsco.asset.command.erc20.transfer operation.

const transferResponse = await axios.post('https://staging.api.fsco.io/v2/asset/erc20/transfer', {
recipient: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
amount: '500000000000000000', // 0.5 tokens with 18 decimals
contractDeploymentId: process.env.CONTRACT_DEPLOYMENT_ID,
signingWalletId: process.env.WALLET_ID
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.TOKEN}`
}
});
const transferTxId = transferResponse.data.queryId;
console.log('Tokens transferred successfully. Transaction ID:', transferTxId);

Approving ERC20 Token Spending

To approve another address to spend tokens on your behalf, use the io.fsco.asset.command.erc20.approve operation.

const approveResponse = await axios.post('https://staging.api.fsco.io/v2/asset/erc20/approve', {
spender: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
amount: '1000000000000000000', // 1 token with 18 decimals
contractDeploymentId: process.env.CONTRACT_DEPLOYMENT_ID,
signingWalletId: process.env.WALLET_ID
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.TOKEN}`
}
});
const approveTxId = approveResponse.data.queryId;
console.log('Approval set successfully. Transaction ID:', approveTxId);

Checking ERC20 Token Balance

To check the balance of ERC20 tokens for a specific address, use the io.fsco.asset.query.erc20.getBalance operation.

const walletAddress = '0x742d35Cc6634C0532925a3b844Bc454e4438f44e';
const contractDeploymentId = process.env.CONTRACT_DEPLOYMENT_ID;
const balanceResponse = await axios.get(`https://staging.api.fsco.io/v2/asset/erc20/balance/${contractDeploymentId}/${walletAddress}`, {
headers: {
'Authorization': `Bearer ${process.env.TOKEN}`
}
});
const balance = balanceResponse.data.balance;
console.log(`Balance for ${walletAddress}: ${balance}`);

Burning ERC20 Tokens

To burn (destroy) ERC20 tokens, use the io.fsco.asset.command.erc20.burn operation.

const burnResponse = await axios.post('https://staging.api.fsco.io/v2/asset/erc20/burn', {
from: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
amount: '500000000000000000', // 0.5 tokens with 18 decimals
contractDeploymentId: process.env.CONTRACT_DEPLOYMENT_ID,
signingWalletId: process.env.WALLET_ID
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.TOKEN}`
}
});
const burnTxId = burnResponse.data.queryId;
console.log('Tokens burned successfully. Transaction ID:', burnTxId);

Conclusion

You’ve successfully learned how to manage ERC20 tokens using the FSCO Asset Service. These operations form the foundation for integrating ERC20 token functionality into your applications.

For more advanced operations, such as batch balance checking or using the transferFrom function, refer to our Advanced ERC20 Operations guide.

Full Script
import axios from 'axios';
import axios from 'axios';
// Minting ERC20 Tokens
const mintResponse = await axios.post('https://staging.api.fsco.io/v2/asset/erc20/mint', {
to: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
amount: '1000000000000000000', // 1 token with 18 decimals
contractDeploymentId: process.env.CONTRACT_DEPLOYMENT_ID,
signingWalletId: process.env.WALLET_ID
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.TOKEN}`
}
});
const mintTxId = mintResponse.data.queryId;
console.log('Tokens minted successfully. Transaction ID:', mintTxId);
// Transferring ERC20 Tokens
const transferResponse = await axios.post('https://staging.api.fsco.io/v2/asset/erc20/transfer', {
from: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
to: '0xRecipientAddress',
amount: '500000000000000000', // 0.5 tokens with 18 decimals
contractDeploymentId: process.env.CONTRACT_DEPLOYMENT_ID,
signingWalletId: process.env.WALLET_ID
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.TOKEN}`
}
});
const transferTxId = transferResponse.data.queryId;
console.log('Tokens transferred successfully. Transaction ID:', transferTxId);
// Checking ERC20 Token Balance
const walletAddress = '0x742d35Cc6634C0532925a3b844Bc454e4438f44e';
const contractDeploymentId = process.env.CONTRACT_DEPLOYMENT_ID;
const balanceResponse = await axios.get(`https://staging.api.fsco.io/v2/asset/erc20/balance/${contractDeploymentId}/${walletAddress}`, {
headers: {
'Authorization': `Bearer ${process.env.TOKEN}`
}
});
const balance = balanceResponse.data.balance;
console.log(`Balance for ${walletAddress}: ${balance}`);
// Burning ERC20 Tokens
const burnResponse = await axios.post('https://staging.api.fsco.io/v2/asset/erc20/burn', {
from: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
amount: '500000000000000000', // 0.5 tokens with 18 decimals
contractDeploymentId: process.env.CONTRACT_DEPLOYMENT_ID,
signingWalletId: process.env.WALLET_ID
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.TOKEN}`
}
});
const burnTxId = burnResponse.data.queryId;
console.log('Tokens burned successfully. Transaction ID:', burnTxId);