0

I am new to Ethereum and I deployed a contract in Ganache which has a function like this:

function withdraw(uint256 amount) public payable returns(bool) {
    require(accounts[msg.sender].balance >= amount);
    accounts[msg.sender].balance -= amount;
    bool r = msg.sender.send(amount);
    if (!r){
        accounts[msg.sender].balance += amount;
    }
    return r;   
}

Then, I use Truffle console to send transactions calling function withdraw. I expected there should be two transactions: one is calling function withdraw and another is the contract sending ether to the sender, which is a result of msg.sender.send(amount).

But I only got one transaction in Ganache which about calling function withdraw.

Am I understanding <address>.send() wrong?

Troublor
  • 159
  • 2
  • 11

1 Answers1

1

This answer is quoted from others.

The transfer() or send() or call() function doesn't result in a transaction. It results in a message call inside the original transaction initiated by an external account. The blockchain will record a single transaction no matter how many transfer() or call() or send() invocations there are in the code.

I just put the link here for reference.

Troublor
  • 159
  • 2
  • 11