How to Lock an NFC Tag
How to Lock an NFC Tag (Make Read-Only)
Locking a tag prevents it from being rewritten, which is useful for permanent installations. This is an option within the write() method. Warning: This action is irreversible.
async function writeAndLockNfcTag() {
try {
const writer = new NDEFReader();
await writer.write(
{ records: [{ recordType: 'text', data: 'This is a permanent message.' }] },
{ overwrite: false } // Prevent writing to a tag that already has data
);
// After writing, you can make the tag permanently read-only.
await writer.makeReadOnly();
console.log('Tag written and locked successfully!');
} catch (error) {
console.error('Error locking tag:', error);
}
}