Development
...
Querying Data from Blockchain
List all messages of an account
1 min
as described in docid\ irb1d8bdsp2b 6fzkfldl signum supports a lot of different transactions one type of transactions are messages this example shows how to filter by transaction types demonstrating it with messages const { isattachmentversion, transactiontype, transactionarbitrarysubtype, address } = require('@signumjs/core'); const {chaintime} = require('@signumjs/util') // here we check for a certain attachment type, and get the text message if not encrypted const getmessagetext = transaction => isattachmentversion(transaction, 'encryptedmessage') ? '\<encrypted>' transaction attachment message; async function listmessages(account) { try { const accountid = address create(account) getnumericid() const ledger = ledgerclientfactory createclient({ nodehost "https //europe3 testnet signum network" }); // here we can explicitly filter by transaction types const {transactions} = await ledger account getaccounttransactions( { accountid, lastindex 20, // getting only the most recent 20 type transactiontype arbitrary, subtype transactionarbitrarysubtype message } ); // now we iterate through the transactions and print in a formatted way transactions foreach(t => { console info(`on ${chaintime fromchaintimestamp(t blocktimestamp) getdate()}`) console info(`from ${t senderrs}`) console info(`to ${t recipientrs}`) console info('message \n', getmessagetext(t), '\n ') }) } catch (e) { console error(e) } } (async () => { await listmessages("ts qaja qw5y swvp 4rvp4"); })();