current position:Home>The three methods of Ganache + truss are different in obtaining the ether balance

The three methods of Ganache + truss are different in obtaining the ether balance

2022-02-03 23:28:25 Q & A of Denglian community

use ganache+truffle, Call the smart contract to get the Ethernet balance , Use web3.eth.getBalance, And use remix In order to get , The three results are different

The contract acquisition method is like this :function getMyBalanceInEth(address addr) public view returns(uint) {return addr.balance;}

  1. Call the contract at the front end :const { getMyBalanceInEth } = this.meta.methods;const amount = await getMyBalanceInEth(this.allaccounts[0]).call();alert(amount); result :180143885539597660000000000

  2. Use... On the front end web3( The result is right , and ganache According to the same )web3.eth.getBalance result :99555222160000000000

3. stay remix-ide Deploy and call the result :99495222160000000000( The result is just different from the correct result 0.06 An ether )

Ask experts to help see what's wrong , thank you






Other answers 1:


Other answers 2:

copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032328231578.html

Random recommended