Writing and reading memos
Memos are available in every transaction and can be quite useful to label your transactions or pass metadata useful to your business logic.
Writing a memo
// Create the JSON object you want to include in the memo
const memoData = {
invoice_id: '12345',
description: 'Coffee and Milk',
date: '2024-07-02'
};
// Convert JSON object to a string and then to hex
const memoJson = JSON.stringify(memoData);
const memoHex = Buffer.from(memoJson, 'utf8').toString('hex');
// Create the Memo field
const memo = {
Memo: {
MemoData: memoHex
}
};
const tx = {
TransactionType: "Payment",
Account: wallet1.classicAddress,
Destination: wallet2.classicAddress,
Amount: "1234",
Memos: [memo]
};
const result = await client.submitAndWait(tx, {
autofill: true,
wallet: wallet1,
});
console.log(result)Decoding memos
Putting it all together
Last updated

