Getting crypto asset information
This article will walk you through the steps to access the test blockchain to get token information.
This time, we will use the G.U.Sandbox Chain which is an Etnereum compatibility test chain, and the 「TUTORIAL」 token has already been issued for this tutorial on that chain, so let's get that information.
In Ethereum, a program registered in the blockchain is always given a unique value called a contract address. The address of the Tutorial Coin to be accessed this time is 0x9C19fB1e8c0773eE5f6B6FE95ea711279F524534
。You can check this information from Block Explorer here
Create program
Now, let's create a javascript file first.
echo > getname.js
Write the following program in the created getname.js and save it
const erc20BasicLib = require("@gusdk/erc20-basic")
const ethers = require('ethers')
async function getTokenName(tokenAddress) {
endpointUrl = 'https://sandbox1.japanopenchain.org:8545/'
const provider = new ethers.providers.JsonRpcProvider({url:endpointUrl})
const coin = erc20BasicLib.ERC20Basic__factory.connect(tokenAddress, provider);
return await coin.name()
}
const tokenAddress = '0x9C19fB1e8c0773eE5f6B6FE95ea711279F524534'
getTokenName(tokenAddress).then(value => console.log(value));
Let's run the program.
> node getname.js
TUTORIAL
You got the name of the token. See the reference for other features.
NOTE: Install the wallet and get a testnet token for future tutorials.