0

Solidity documentation:

You should avoid using .call() whenever possible when executing another contract function as it bypasses type checking, function existence check, and argument packing.

Ethereum Smart Contract Best Practices:

It's recommended to stop using .transfer() and .send() and instead use .call().

Is there a consensus on which method is best?

1

The recommendations are under different circumstances:

  • Solidity developers recommend against using .call() when invoking a function from a contract.

    You should avoid using .call() whenever possible when executing another contract function as it bypasses type checking, function existence check, and argument packing.

    In this case you should use an interface when invoking another contract. So the compiler can check and generate the correct call.

  • Consensys guidelines are in the context of Ether transfer

    .transfer() and .send() forward exactly 2,300 gas to the recipient. [...] It's recommended to stop using .transfer() and .send() and instead use .call().

    Also they state that you should be aware that you will have to consider reentrancy attacks.

    Note that .call() does nothing to mitigate reentrancy attacks, so other precautions must be taken.

    There's no perfect alternative to .transfer() for protection against reentrancy attacks.

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.