Just like Ethereum, you can send some KLAY to contracts. There are couple things you need to remember though.
Make sure you have fallback function with payable
modifier
If you are from Ethereum, then you are probably familiar with this: to receive Ether and add it to the total balance, a contract must have fallback function marked with payable
. The same rule applies to Klaytn. A contract must have one (and only one) unnamed function — a.k.a. fallback function — with payable
modifier in order to receive KLAY. Without such, a contract cannot receive KLAY through regular transactions and throws an exception.
Here’s an example contract with payable fallback function:
contract WithFallbackPayable {
event FallbackCalled(uint amount);
function () external payable {
emit FallbackCalled(msg.value);
}
}
Use LEGACY
transaction to send KLAY
You must use LEGACY
transactions when you send KLAY to contracts. Since VALUE_TRANSFER
transactions are strictly allowed for KLAY transfer between EOAs, Klaytn will decline any VALUE_TRANSFER
transaction if it contains a non-EOA address in to
field.