Search code examples
smartcontractsmultiversx

How to send EGLD value to smart contract endpoint?


I have a smart contract method that looks like this:

#[payable("EGLD")]
#[endpoint(myEndpoint)]
fn my_endpoint(&self, #[payment_amount] payment: BigUint, some_value: u64) { ... }

And I call it with 5 EGLD value in transaction along with tx data

myEndpoint@05@aa

but tx result returns me wrong number of arguments.

What am I doing wrong?


Solution

  • Payment args in EGLD are auto-filled from the call value you've already specified in the transaction, so you do not need to pass them as argument.

    Therefore, your call data in this case would be myEndpoint@aa, without the payment arg.

    As a side note, if this would've been an endpoint accepting another token than EGLD, you would've had to specify the token and amount in the data field, like: ESDTNFTTransfer@TokenIdentifier_in_hex@TokenNonce_in_hex@TokenValue_in_hex@Contract_address_in_hex@myEndpoint_in_hex@aa.

    The ESDTNFTTransfer function sends any type of ESDT token, with or without nonce. If the token doesn't have a nonce (fungible), you can either pass 00 as nonce or leave the nonce space empty, like @TokenName_in_hex@@TokenValue_in_hex. Mind the fact that in order to use this function, you would have to compose a transaction with the destination set as yourself. The actual address of the destination would be contained in the data field in place ofContract_address_in_hex, making it a parameter of the ESDTNFTTransfer function.

    If the endpoint accepted two tokens for example, then you could've used MultiESDTNFTTransfer@Contract_address_in_hex@02@Token1Identifier_in_hex@Token1Nonce_in_hex@Token1Value_in_hex@Token2Identifier_in_hex@Token2Nonce_in_hex@Token2Value_in_hex@myEndpoint_in_hex.

    And yeah, you can always check the MultiversX docs on ESDT Tokens / NFT Tokens for more details.