Skip to content

Instantly share code, notes, and snippets.

@zquestz
Last active September 15, 2021 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zquestz/fad9ccf9ffe9be5425583100778754b2 to your computer and use it in GitHub Desktop.
Save zquestz/fad9ccf9ffe9be5425583100778754b2 to your computer and use it in GitHub Desktop.
const TOKEN_CONTRACT_ADDRESS="0xc70c7718C7f1CCd906534C2c4a76914173EC2c44"
const YOUR_ETH_ADDRESS="0x6cdde7dd0acc56cabfc2315791016f7c334d72c3"
// The minimum ABI to get SEP20 Token balance
const minABI = [
{
constant: true,
inputs: [{ name: "_owner", type: "address" }],
name: "balanceOf",
outputs: [{ name: "balance", type: "uint256" }],
type: "function",
},
{
constant: true,
inputs: [],
name: "decimals",
outputs: [{ name: "", type: "uint8" }],
type: "function",
},
];
// Get SEP20 Token contract instance
const contract = new web3js.eth.Contract(minABI, TOKEN_CONTRACT_ADDRESS)
// Call balanceOf function
const result = await contract.methods.balanceOf(YOUR_ETH_ADDRESS).call();
const format = Web3NoMeta.utils.fromWei(result);
console.log(format);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment