Overview
Theaccount_transfer syscall transfers a specified amount of balance from one account to another. Both accounts must exist and meet writability requirements.
Syscall Code
Code:0x03 (TN_SYSCALL_CODE_ACCOUNT_TRANSFER)
C SDK Function
Arguments
Index of the source account to transfer balance from. Must be writable by the current program.
Index of the destination account to transfer balance to. Must be writable in the transaction.
Amount of balance to transfer from source to destination account.
Return Value
Returns a syscall result code:TN_VM_SYSCALL_SUCCESS(0) - Transfer completed successfully
TN_VM_ERR_SYSCALL_INVALID_ACCOUNT_INDEX(-7) - Invalid from or to account indexTN_VM_ERR_SYSCALL_ACCOUNT_NOT_WRITABLE(-26) - From account not writable by program or to account not writable in transactionTN_VM_ERR_SYSCALL_ACCOUNT_DOES_NOT_EXIST(-8) - Source or destination account does not existTN_VM_ERR_SYSCALL_INSUFFICIENT_BALANCE(-37) - Source account has insufficient balanceTN_VM_ERR_SYSCALL_INVALID_ACCOUNT(-26) - Either account is ephemeral (not allowed for transfers)TN_VM_ERR_SYSCALL_BALANCE_OVERFLOW(-10) - Destination balance would overflow
Resource Consumption
Compute Units
- Base cost:
TN_VM_SYSCALL_BASE_COST(512 units) - Additional cost: None
- Total cost: Fixed at 512 units regardless of transfer amount
Memory Pages
- Page usage: No direct page allocation or deallocation
- Metadata impact: May trigger metadata page allocation for both accounts if not already writable
Side Effects
- Balance modification: Decreases source account balance and increases destination balance
- Account metadata: Makes account metadata writable if not already
Usage Notes
- Both accounts must be non-ephemeral accounts
- Source account must be writable by the current program
- Destination account must be writable in the transaction (signer approval)
- Transfer amount cannot exceed source account balance
- Destination balance cannot overflow (exceed maximum value)
- Account metadata is automatically made writable for both accounts