The ledger history is the record of how the ledger state came to be. It is represented by the set of vote staples which have been applied to the ledger.
This is expressed in two different ways in the KeetaNet SDK
The UserClient.chain method which returns a list of blocks which have been applied for a given account.
These two differ in that the history method returns all vote staples which affected an account, even if they were not issued by the account -- for example if a transfer was made to the account, the history method would return the vote staple which included the transfer, but the chain method would not because it was not issued by the account.
Additionally there is a method to filter a list of vote staples to a list of operations which are relevant to a specific account. This is useful because the list of operations in a vote staple may include changes that are uninteresting from an account perspective.
History via predefined seed
The script above demonstrates how to connect to the KeetaNet testnet and retrieve the account history using a predefined demo seed.
import*asKeetaNetfrom'@keetanetwork/keetanet-client';importutilfrom'node:util';// Demo seed β Replace with real seed constDEMO_SEED='D3M0D3M0D3M0D3M0D3M0D3M0D3M0D3M0D3M0D3M0D3M0D3M0D3M0D3M0D3M0D3M0';asyncfunctionmain(){ // Create an account from the seed (index 0)constaccount=KeetaNet.lib.Account.fromSeed(DEMO_SEED,0); // Connect to KeetaNet testnet using the accountconstclient=KeetaNet.UserClient.fromNetwork('test',account); // Fetch the account historyconsthistory=awaitclient.history(); // Print the account history in readable formatconsole.log('π Account history:',util.inspect(KeetaNet.lib.Utils.Helper.debugPrintableObject(history),{depth:10,colors:true}) );}main().catch((err)=>{console.error('β Error:',err);process.exit(1);});
History of a public account
To retrieve the transaction history using a public Keeta address, you can use the provided script that demonstrates connecting to the KeetaNet testnet. By substituting a valid KeetaNet public key string, the script fetches the account's transaction history.
import * as KeetaNet from '@keetanetwork/keetanet-client';
import util from 'node:util';
async function main() {
// Replace this with any valid KeetaNet public key string
const publicKeyString = 'keeta_aabrrk5663nikbzhc3vr24nvwabyseqvlbf4ritnsoca2ujfurk6jqprplnm66y';
// Create an account object from the public key string
const account = await KeetaNet.lib.Account.fromPublicKeyString(publicKeyString);
// Connect to the KeetaNet testnet
const client = KeetaNet.UserClient.fromNetwork('test', null, { account });
// Fetch the account's transaction history
const history = await client.history();
// Display the history in a readable format
console.log(
'π Account history for', publicKeyString,
util.inspect(KeetaNet.lib.Utils.Helper.debugPrintableObject(history), {
depth: 10,
colors: true
})
);
}
main().catch((err) => {
console.error('β Error:', err);
process.exit(1);
});