Skip to content

Writing & Formatting

Building NDEF Messages

createNDEFUrl(url)

Build an NDEF message containing a single URL record. Returned directly as a Buffer (no result wrapper, no tag I/O).

const ndef = tag.createNDEFUrl('https://example.com/t');
// → <Buffer ...> (NDEF message Buffer)

createNDEFText(text, language?)

Build an NDEF message containing a single text record. language defaults to 'en'. Returned directly as a Buffer.

const ndef = tag.createNDEFText('Hello', 'en');
// → <Buffer ...> (NDEF message Buffer)

Writing Files

writeNDEF(ndefData)

Write NDEF data directly to file 2 (no SDM encoding; auth: the NDEF file’s write key, automatic). Use createNDEFUrl / createNDEFText to build the message.

const res = await tag.writeNDEF(tag.createNDEFUrl('https://example.com/t'));

Returns

{
success: true,
data: {
fileNo: 2,
offset: 0,
bytesWritten: 24,
mode: 'iso'
},
duration: 22
}

writeProprietary(proprietaryData)

Write proprietary data to file 3 (UTF-8, with an automatic 2-byte length prefix — no padding; auth: the file’s write key, automatic). proprietaryData is a string or Buffer.

const res = await tag.writeProprietary('serial:12345');

Returns

{
success: true,
data: {
fileNo: 3,
offset: 0,
bytesWritten: 14, // 2-byte length prefix + 'serial:12345' (12 bytes)
mode: 'iso'
},
duration: 31
}

writeCapabilityContainer(options?)

Set the CC (file 1) with custom access rights for the NDEF and Proprietary files. Each of options.ndefRead, ndefWrite, proprietaryRead, proprietaryWrite is a number 0–4, 'free', or 'never'.

const res = await tag.writeCapabilityContainer({ ndefRead: 'free', ndefWrite: 0 });

Returns

{
success: true,
data: {
fileNo: 1,
accessRights: {
ndef: { read: 'free', write: 0 },
proprietary: { read: 2, write: 3 } // omitted in the call → default Key 2 / Key 3
}
},
duration: 18
}

Clearing & Resetting

clearFile(fileNo)

Clear a file (zeros with the correct structure for that file type). fileNo — 1=CC, 2=NDEF, 3=Proprietary.

const res = await tag.clearFile(2);

Returns

{
success: true,
data: {
fileNo: 2,
message: 'Cleared file successfully'
},
duration: 20
}

formatTag()

Factory reset: clear all files, disable SDM, restore default settings, and reset all keys to 00…00 (auth: Key 0, automatic).

const res = await tag.formatTag();

Returns

{
success: true,
data: {
operationList: {
clearFiles: { fileCC: true, fileNDEF: true, fileProprietary: true },
disableSDM: true,
changeFileSettings: { fileCC: true, fileNDEF: true, fileProprietary: true },
changeKeys: true
}
},
duration: 45
}