0

so the goal here is to get the balance of the connected account and display it in the table. Ive been working on this all day and im feeling stuck. Heres what I have:


         function App(){
 
 ///.....////
 
 
 const Web3 = require("web3");
  const web3 = new Web3(
    Web3.givenProvider ||
      "https://ropsten.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"
  );

  async function checkBalance() {
    try {
      await web3.eth.getBalance(account).then(web3.utils.fromWei());
    } catch (error) {
      console.log(error);
    }
  }
  
  
  ////.....//// {checkBalance} to be displayed in a table
  
  <Table variant="striped" width="100%">
            <TableCaption>Token balances of {account}</TableCaption>
            <Thead>
              <Tr>
                <Th>Token</Th>
                <Th>Contract Address</Th>
                <Th>Balance</Th>
              </Tr>
            </Thead>
            <Tbody>
              <Tr>
                <Td>ETH</Td>
                <Td>0x0000000000000000000000000000000000000000</Td>
                <Td>{checkBalance}</Td>
              </Tr>
            </Tbody>
            <Tfoot>
              <Tr>
                <Th>Token</Th>
                <Th>Contract Address</Th>
                <Th>Balance</Th>
              </Tr>
            </Tfoot>
          </Table>
2
  • Hi Atticus! This question isn't related to Ethereum, you have to learn how to deal with http request to fill a table from react.
    – Ismael
    Oct 28 at 5:25
  • await web3.eth.getBalance(account).then(web3.utils.fromWei()); this is wrong not sure if then and await work in the same line
    – Majd TL
    Oct 29 at 9:54

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.