0

sorry if this is very googlable,but i coudnt manage to find good info so far.

I want to read balances of particular adresses on different smart contracts, and even better if i can get the value of staked tokens like crvAave for exmample. So,like a zapper clone, as i want to learn by doing this.

From the documentation at web3 and ethers.js i coudnt find how to look for it yet.

Thanks so much in advance!

5
  • You would have to look at the documentation of the specific contract you want to query (or even better, look at the contract directly), it should have a view function that returns that kind of info. Sushiswap masterchef for example calls it userInfo()
    – Foxxxey
    Sep 25 at 23:44
  • 1
    Or are you trying to get the balance of an address for a particular token? if yes you want to call the token contracts code balanceOf() function
    – Foxxxey
    Sep 25 at 23:46
  • Thanks Foxxxey! Im trying to get the balance depoosited of an adress in a smart contract. For example if i deposited in sushi ETH/USDC, i want to get the staked tokens/value $ of my adress. So to build a zapper type of clone, i would have to scan all the main contracts on ethereum and do the balanceOf( ) i guess?
    – Joa0
    Sep 25 at 23:54
  • If you deposited ETH/USDC LP tokens, your tokens are in masterchef. To retrieve your balance in that contract (at address 0xef0881ec094552b2e128cf945ef17a6752b4ec5d on ETH mainnet) you'd have to query its userInfo function. It take 2 parameters, an address (thats your wallet address) and a pid (thats the internal ID used by the contract to refer to the ETH/USDC pool, you can find it by looking at a transaction where you deposited/harvested/withdrew from this pool). It returns 2 numbers, the data you want to get is the 1st one, that will give you the number of LP tokens you have staked...
    – Foxxxey
    Sep 26 at 0:10
  • ... in wei, just divide by 1e18 to get the number of tokens. Now if you want to get the $ value of those that's trickier, you might want to look at how sushiswap implemented it on their frontend, im not sure myself.
    – Foxxxey
    Sep 26 at 0:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.