---
title: set_account_data_writable
description: Marks an account's data as writable by the current program
source_url:
  html: https://thru.org/docs/spec/vm/syscalls/set_account_data_writable/
  md: https://thru.org/docs/spec/vm/syscalls/set_account_data_writable.md
---

# set_account_data_writable

## 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

**Code:** `0x02` (`TN_SYSCALL_CODE_SET_ACCOUNT_DATA_WRITABLE`)

## C SDK Function

```c
ulong tsys_set_account_data_writable(ulong account_idx);
```

## Arguments

**`account_idx` · *ulong* · **required****

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

## 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 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

## Resource Consumption

### 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

- **Page usage**: No direct page allocation or deallocation
- **Metadata impact**: May trigger metadata page allocation if account metadata becomes writable

## 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

- 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

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

```c
#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
}
```
