Delete an Audit Trail
This guide shows how to permanently remove an AuditTrail object from the IOTA network. A trail can only be deleted once all of its records have been removed.
Prerequisites
- An existing
AuditTrailobject on the IOTA network containing several (less than 10 for this example) records - The trail must not have a delete-trail lock set (see Configure Locking)
- An admin address owning an admin role capability as been shown in Create an Audit Trail
Steps
1. Set Up Multiple Wallets
Create an admin wallet and a maintenance-admin wallet that will be delegated the permissions needed to empty and delete the trail.
Used Utility Functions
2. Create a Role with Deletion Permissions
Define a role that has both DeleteAllRecords (to empty the trail) and DeleteAuditTrail (to remove the trail itself).
3. Attempt to Delete a Non-Empty Trail
Deleting a trail that still contains records fails. This constraint ensures no data is silently lost.
4. Empty the Trail with Batch Deletion
Remove the records using delete_records_batch / deleteBatch. The call deletes unlocked records from the front of the trail and returns the sequence numbers it removed; any locked records are skipped. Since this trail has no active delete lock, a single batch empties it — verify the record count reaches zero.
5. Delete the Empty Trail
With no records remaining, the trail can now be permanently deleted.
Expected Behavior
- Attempting to delete a non-empty trail returns an error.
- After batch-deleting all records, the trail can be successfully deleted.
- Once deleted, the trail is no longer readable on-chain — any
get()call returns an error.
Trail deletion is permanent and irreversible. Ensure you have exported or archived any data you need before deleting.
Running Examples Locally
In order to run the examples, you will need to run an IOTA network locally. See the local network setup guide.
Full Example Code
- Rust
- Typescript (Node.js)
loading...
loading...