Get the App
SLTechnology News&Howtos  ›  Development  › 

How to compare the transfer methods of call, send and transfer

Shulou Source: shulou.com Published: 2022-06-02 10:29:50 10月03日 Update

This article is about how to conduct call, send and transfer transfer methods and comparison, the editor feels very practical, so share with you to learn, I hope you can learn something after reading this article, say no more, follow the editor to have a look.

Three ways of transferring money 1

two

three

Address.transfer ()

Address.send ()

Address.call.value () .gas ()

Transfer transfer1

two

three

four

five

six

seven

eight

nine

ten

Function transfer (address _ address) public payable {

_ address.transfer (msg.value)

}

Function transfer2 (address _ address) public payable {

_ address.transfer (10 * 10 / 18)

}

Transfer send1

two

three

Function transfer4 (address _ address) public payable {

_ address.send (10 ether)

}

Transfer call1

two

three

Function transfer5 (address _ address) public payable returns (bool) {

Return _ address.call.value (10 ether) ()

}

Comparison and summary 1

two

three

four

five

six

Transfer, similar to send, is a transfer operation.

Transfer makes an error and throws an exception

If an error occurs in send or call, no exception is thrown, but true or false is returned.

Tansfer is more secure than send

Send and call will execute the following code even if the transfer fails.

Be careful to use the call function to transfer money, it is easy to reenter.

The above is how to compare the transfer methods of call, send and transfer. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Transfer method more knowledge article practical similar security code function that is work meeting article look knowledge point industry details information channel follow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MariaDB Xiaomi macOS OPPO Reno