Skip to content

set_account_data_writable

View as Markdown

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.

Code: 0x02 (TN_SYSCALL_CODE_SET_ACCOUNT_DATA_WRITABLE)

ulong tsys_set_account_data_writable(ulong account_idx);

account_idx · ulong · required

Index of the account to mark as writable. Must be a valid account index within the transaction.

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 bounds
  • TN_VM_ERR_SYSCALL_ACCOUNT_NOT_WRITABLE (-10) - Account not writable in transaction or ownership check failed
  • TN_VM_ERR_SYSCALL_ACCOUNT_DOES_NOT_EXIST (-9) - Account does not exist
  • Base cost: TN_VM_SYSCALL_BASE_COST (512 units)
  • Additional cost: None
  • Total cost: Fixed at 512 units regardless of account state
  • Page usage: No direct page allocation or deallocation
  • Metadata impact: May trigger metadata page allocation if account metadata becomes writable
  • Account state: Marks the account as writable by the current program
  • Write permissions: Grants the program ability to modify account data
  • 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

The account can be made writable only if:

  • The account is not a program account
  • The account is owned by the current executing program
#include <thru-sdk/c/tn_sdk_syscall.h>
// Mark account at index 1 as writable
ulong 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
}