I am using accounts[2]. Truffle console is showing the transaction of calling the ‘testFunc’ but the
balance of SC and the accounts[2] i.e. acc2 is not changing:
Sorry, I am not sure what do you mean acc2 is not changing, according to your log in the truffle console:
before calling testFunc()
web3.utils.fromWei(balance, "ether"). <<----- eth balance of the contract.
web3.utils.fromWei(b2, "ether") <<----- eth balance of the account2.
= 100.000000000000000097
after calling testFunc()
web3.utils.fromWei(b2, "ether"). <<----- eth balance of the account2.
=100.000000000000000194
so you can see the result as above, the eth balance of the account2 has increased 97 as expected.
Maybe you also need to check the current eth balance of the contract.
Ohhh, I see, cause you defined in the contract as this: uint8 public testVal =97, so every time, the balance increases 97 wei, if you want to make it become 97 ether, I think you can define as following: uint256 public testVal = 97e18;.
Kind reminder, if you rewrite like above, 97e18 is equal to 97 eth, this is really a large mount of money!
pragma solidity ^0.5.1;
contract TransferTest{
uint public testVal =97 ether;//Note we can't use uint8 with 97 ether
function testFunc(address payable addr) public returns (uint) {//when we use payable SC would receive Ether
//addr.transfer(msg.value); We can't use msg.value, it would //give an error, msg.value can be used only if function is payable
addr.transfer(testVal);
return testVal;
}
function deposit() payable public{}
}