Skip to main content

Overview

The account_delete syscall marks an account as deleted by setting the DELETED flag. The account must have zero balance and be writable by the current program.

Syscall Code

Code: 0x06 (TN_SYSCALL_CODE_ACCOUNT_DELETE)

C SDK Function

ulong tsys_account_delete(ulong account_idx);

Arguments

account_idx
ulong
required
Index of the account to delete. Must be writable by the current program and have zero balance.

Return Value

Returns a syscall result code:
Success
ulong
  • TN_VM_SYSCALL_SUCCESS (0) - Account marked as deleted successfully
Error Codes
ulong
  • TN_VM_ERR_SYSCALL_INVALID_ACCOUNT_INDEX (-7) - Account index out of bounds
  • TN_VM_ERR_SYSCALL_ACCOUNT_DOES_NOT_EXIST (-8) - Account does not exist
  • TN_VM_ERR_SYSCALL_ACCOUNT_NOT_WRITABLE (-26) - Account not writable by current program
  • TN_VM_ERR_SYSCALL_INVALID_ACCOUNT (-26) - Account has non-zero balance

Resource Consumption

Compute Units

  • Base cost: TN_VM_SYSCALL_BASE_COST (512 units)
  • Additional cost: None
  • Total cost: Fixed at 512 units

Memory Pages

  • Page usage: No immediate page deallocation (pages freed during garbage collection)
  • Metadata impact: May trigger metadata page allocation if not already writable
  • Future cleanup: Pages will be reclaimed after transaction completion

Side Effects

  • Account state: Sets the DELETED flag on the account
  • Metadata: Makes account metadata writable if not already
  • Data retention: Account data and metadata remain accessible until garbage collection

Usage Notes

  • Account must have exactly zero balance before deletion
  • Only the account owner (program) can delete the account
  • Deleted accounts can be recreated with account_create (removes DELETED flag)
  • Account data remains accessible during the transaction even after deletion
  • The account becomes eligible for garbage collection after transaction completion

Deletion vs Compression

OperationPurposeRequirementsEffect
DeleteRemove accountZero balance, ownershipSets DELETED flag
CompressArchive accountState proofSets COMPRESSED flag

Example

#include "tn_sdk_syscall.h"

// Delete an account (must have zero balance)
ulong account_idx = 2;

// First ensure the account has zero balance
// (transfer out any remaining balance first)

ulong result = tsys_account_delete(account_idx);

if (result == TN_VM_SYSCALL_SUCCESS) {
    // Account marked as deleted
    // Will be garbage collected after transaction
    // Can still access data during this transaction
    // Can be recreated with account_create
}