set_account_data_writable
Overview
Section titled “Overview”The set_account_data_writable syscall marks an account’s data as writable by the current executing program. This grants the program permission to modify the account’s data and metadata.
Syscall Code
Section titled “Syscall Code”Code: 0x02 (TN_SYSCALL_CODE_SET_ACCOUNT_DATA_WRITABLE)
C SDK Function
Section titled “C SDK Function”ulong tsys_set_account_data_writable(ulong account_idx);Arguments
Section titled “Arguments”account_idx · ulong · required
Index of the account to mark as writable. Must be a valid account index within the transaction.
Return Value
Section titled “Return Value”Returns a syscall result code:
Success · ulong
TN_VM_SYSCALL_SUCCESS(0) - Account successfully marked as writable
Error Codes · ulong
TN_VM_ERR_SYSCALL_INVALID_ACCOUNT_INDEX(-8) - Account index out of boundsTN_VM_ERR_SYSCALL_ACCOUNT_NOT_WRITABLE(-10) - Account not writable in transaction or ownership check failedTN_VM_ERR_SYSCALL_ACCOUNT_DOES_NOT_EXIST(-9) - Account does not exist
Resource Consumption
Section titled “Resource Consumption”Compute Units
Section titled “Compute Units”- Base cost:
TN_VM_SYSCALL_BASE_COST(512 units) - Additional cost: None
- Total cost: Fixed at 512 units regardless of account state
Memory Pages
Section titled “Memory Pages”- Page usage: No direct page allocation or deallocation
- Metadata impact: May trigger metadata page allocation if account metadata becomes writable
Side Effects
Section titled “Side Effects”- Account state: Marks the account as writable by the current program
- Write permissions: Grants the program ability to modify account data
Usage Notes
Section titled “Usage Notes”- The account must be marked as writable in the transaction (signer approval)
- The account must be owned by the current program
- Program accounts cannot be made writable
- If the account is already writable by the current program, the syscall succeeds immediately
- Once writable, the program can modify account data and metadata
Ownership Rules
Section titled “Ownership Rules”The account can be made writable only if:
- The account is not a program account
- The account is owned by the current executing program
Example
Section titled “Example”#include <thru-sdk/c/tn_sdk_syscall.h>
// Mark account at index 1 as writableulong account_idx = 1;ulong result = tsys_set_account_data_writable(account_idx);
if (result == TN_VM_SYSCALL_SUCCESS) { // Account is now writable by this program // Can now modify account data and metadata}