We have three main ways to send Ether in Rust Stylus:
transfer_ethcallCall::new_payable)Important: transfer_eth in Stylus invokes the recipient contract and forwards execution with your full call gas (the callee can spend it and even make further calls). In Solidity, transfer historically forwarded only 2,300 gas. In Stylus, if you need to cap gas, use the low-level call and set a gas limit on the Call context.
These two are equivalent under the hood:
1transfer_eth(self.vm(), recipient, value)?;
2call(self.vm(), Call::new_payable(self, value), recipient, &[])?;1transfer_eth(self.vm(), recipient, value)?;
2call(self.vm(), Call::new_payable(self, value), recipient, &[])?;receive() (no calldata): Send Ether without calldata.fallback() (with calldata): Send Ether with calldata.payable function (e.g., receiveEther()), passing value via Call::new_payable.Call::new_payable(self, value).gas(limit) when you must cap recipient gas.receive()/fallback()/payable handlers.Below you can find examples for each of these methods and how to define them in a Rust Stylus smart contract using the Stylus SDK:
1Loading...1Loading...1Loading...1Loading...1Loading...1Loading...