0

I am trying to understand the test provided at:

Tutorial

("Test balance after deposit", function() {
        return SimpleBank.deployed().then(function(instance) {
            sb = instance;
            return sb.deposit({ from: accounts[0], value: web3.utils.toWei('10', 'ether') });
        })

The smart contract code is given below:

contract SimpleBank{
   uint public transactions;
   mapping (address=>uint) balances;
   
   function deposit() public payable{
      balances [msg.sender] +=msg.value;
      transactions++;
   }
}

The test invokes :

sb.deposit({ from: account[0], value:  web3.utils.toWei('10', 'ether') });

To which account the ‘10’ ether is going from account[0]? What is the purpose of 'transactions' state variable?

2

The 10 Ethers goes to the contract SimpleBank and stays there. In the deposit function the contract sets some additional data which marks who sent how much Ethers, but this is only contract's internal book-keeping and doest't move any Ethers anywhere.

As for the transactions variable, it probably just shows how to use a state variable. It doesn't have any real benefit, it's just an example. As is all of the contract - just an example for reference purposes.

1
  • how can we check the balance of SimpleBank?
    – zak100
    Jan 20 at 18:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.