Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Solidity Only - you are to complete this problem using Solidity. Deploy a utility EVM contract with a function to retrieve all token balances given

Solidity Only - you are to complete this problem using Solidity.

Deploy a utility EVM contract with a function to retrieve all token balances given a wallet address and the token contract addresses.

How your contract will be tested:

./test.js

const { ethers } = require("ethers");

const ADDR = ""; // your contract address

const ABI = []; // your contract ABI

const ADDRESS = ""; // some wallet address with token balance

const TOKENS = [ // token contract addresses "", "", ];

// you can use your own RPC provider url (no need to deploy to mainnet)

const provider = ethers.providers.getDefaultProvider();

const test = async () => {

const contract = new ethers.Contract(ADDR, ABI, provider);

const balances = await contract.getBalances(ADDRESS, tokens); return balances; };

test().then(console.log);

The output should be organized as one token amount per object.

[ { token: "0x123d475e13aa54a43a7421d94caa4459da021c77", balance: "9988887462734227" // its okay if this is typed ethers.BigNumber }, { token: "0x55f6823de9642f47e80ed4845a55aa8430cb4ec6", balance: "899998285714286" }, ]

You may need to use the NPM module truffle or hardhat to complete this task.

You can deploy your own token contracts on test networks to retrieve the balances from (mock the data), or you can use existing token contracts on either test or main networks, as long as you can deploy the balance reader contract on the same network.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions