Retrieve Account Transactions History
In this tutorial, we will guide you through the process of retrieving an Account's transaction history using the Eniblock SDK.
Retrieve Native Transfers History​
Live Editor
// Initialize the Eniblock SDK with user, owner and storage detailsconst sdk = new Eniblock({authConfig: {clientId: "50efd4aa-2aa1-499c-87e2-db089409b818",redirectUrl: window.location.origin + "/docs/",},// LocalStorage is used here for demo purposes// WARNING: In a production environment, a remote drive should be usedstorageItems: [{ alias: "LocalStorage", storage: new LocalStorage() }],});try {console.log("Retrieving account history...");// Instantiate the wallet using the SDKconst wallet = await sdk.wallet.instantiate();// Create an account in the walletconst account = await wallet.account.instantiate("My first account");// Fetch the account addressconst accountAddress = await account.getAddress();// Fetch the account's native transfer historyconst history = await account.getNativeTransferHistory();// Loop over each transaction in the historyhistory.forEach((tx) => {// Determine if the transaction is incoming or outgoing based on the 'from' addressconst direction =tx.from.toLowerCase() === accountAddress.toLowerCase()? "sent to": "received from";// Log the transaction details, including its direction (incoming or outgoing)console.log(`${tx.timestamp}: ${tx.value} ${tx.assetSymbol} ${direction} ${direction === "sent to" ? tx.to : tx.from}.`);});} catch (error) {// Log any errors that occur during the processconsole.log(JSON.stringify(error));}
Retrieve All kind of tokens Transfers History​
Live Editor
// Initialize the Eniblock SDK with user, owner and storage detailsconst sdk = new Eniblock({authConfig: {clientId: "50efd4aa-2aa1-499c-87e2-db089409b818",redirectUrl: window.location.origin + "/docs/",},// LocalStorage is used here for demo purposes// WARNING: In a production environment, a remote drive should be usedstorageItems: [{ alias: "LocalStorage", storage: new LocalStorage() }],});try {console.log("Retrieving account history...");// Instantiate the wallet using the SDKconst wallet = await sdk.wallet.instantiate();// Create an account in the walletconst account = await wallet.account.instantiate("My first account");// Fetch the account addressconst accountAddress = await account.getAddress();// Fetch all kind of tokens transfer history of the accountconst history = await account.getAllTokensTransferHistory();// Loop over each transaction in the historyhistory.forEach((tx) => {// Determine if the transaction is incoming or outgoing based on the 'from' addressconst direction =tx.from.toLowerCase() === accountAddress.toLowerCase()? "sent to": "received from";// Log the transaction details, including its direction (incoming or outgoing)console.log(`${tx.timestamp}: ${tx.value? tx.value: 1} ${tx.assetSymbol} ("${tx.assetType}") ${direction} ${direction === "sent to" ? tx.to : tx.from}.`);});} catch (error) {// Log any errors that occur during the processconsole.log(JSON.stringify(error));}
Get the transfer history of Any account​
Live Editor
// Initialize the Eniblock SDK with user, owner and storage detailsconst sdk = new Eniblock({authConfig: {clientId: "50efd4aa-2aa1-499c-87e2-db089409b818",redirectUrl: window.location.origin + "/docs/",},});try {const addressToCheck = "0x8931330bee6581cf134458974e8e8737a453a3fb";console.log(`Retrieving tokens transfer history for the address "${addressToCheck}"...`);// Fetch all kind of tokens transfer history of the accountconst history = await sdk.utils.getAllTokensTransferHistory(addressToCheck, { fromBlock: "0x208bae8", toBlock: "0x208c524" });// Loop over each transaction in the historyhistory.forEach((tx) => {// Determine if the transaction is incoming or outgoing based on the 'from' addressconst direction =tx.from.toLowerCase() === addressToCheck.toLowerCase()? "sent to": "received from";// Log the transaction details, including its direction (incoming or outgoing)console.log(`${tx.timestamp}: ${tx.value? tx.value: 1} ${tx.assetSymbol? tx.assetSymbol: ""} ("${tx.assetType}") ${direction} ${direction === "sent to" ? tx.to : tx.from}.`);});} catch (error) {// Log any errors that occur during the processconsole.log(JSON.stringify(error));}