How to get list of assets and their quantities from an account? #1056
-
Hello, I've been working on the Aave chapter and I wanted to add some additional functionality to the example Patrick is showing us. I know that I can use the method account.balance() to get the balance in Wei, but how do I get the balance in other assets associated with an account? For example how do I get the balance of DAI or WETH etc. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello @JimAtActiv contract MyContract
{
// Private state variable
address private owner;
// Defining a constructor
constructor() public{
owner=msg.sender;
}
// Function to get
// address of owner
function getOwner(
) public view returns (address) {
return owner;
}
// Function to return
// current balance of owner
function getBalance(
) public view returns(uint256){
return owner.balance;
}
} When you get the balance you will have the current balance in ETH the user have, so if you want to get a specific balance of token you must specify the token address on the BalanceOf funtion, you can refer here to more info. |
Beta Was this translation helpful? Give feedback.
Hello @JimAtActiv
Most of the functions related to get the user balance are more a front-end approach, on which you use libraries like use-dapps or services like Moralis. Because the balance you are using on solidity will return the current balance of the network coin your are on (eth for ethereum blockchain) so if you have something like this: