Skip to main content

getTransactionHistory

The getTransactionHistory method is a powerful tool for retrieving all transactions associated with a specific wallet address. It enables users to track every transaction, including deposits, withdrawals, and their corresponding details such as transaction hashes, amounts, and timestamps.
With the pageCount parameter, users can request transactions in a paginated manner, making it easy to manage large amounts of data.
This method is particularly useful for applications focused on displaying a user's financial activity, transaction audits, or reporting purposes. It ensures accurate transaction history retrieval with well-structured data and helpful error messages in case of failure.

Usage

import kohin from "./kohinInstance";

const transactionHistoryParams = {
address: "0x670EEBd1eFdf8D576e1FE554F3D8e905f28cc5b9", // Address whose transaction history is being fetched
pageCount: 1, // Pagination parameter to specify which page of history to retrieve
};

const transactionHistory = await kohin.getTransactionHistory(
transactionHistoryParams
);
console.log("Transaction History:", transactionHistory);

Parameters

ParameterTypeDescription
addressstringThe wallet address whose transaction history is being fetched.
pageCountnumberPagination parameter for fetching transaction history (default: 1).

Return Value

Returns a Promise resolving to an object with the following structure:

{
success: boolean; // Indicates whether the call was successful
data?: { // Transaction history object (present if successful)
transactionHistory:
Array<{
account: string;
amount: string;
rawAmount: string;
blockNumber: string;
blockTimestamp: string;
depositId: string;
id: string;
transactionHash: string;
txnType: string;
withdrawalFee?: string;
}>;
};
error?: string; // Error message if the call fails
}

Error Handling

Handle potential errors gracefully by checking the response or using a try-catch block:

try {
const transactionHistory = await kohin.getTransactionHistory({
address: "0x670EEBd1eFdf8D576e1FE554F3D8e905f28cc5b9",
pageCount: 1,
});
if (!transactionHistory.success) {
console.error("Error:", transactionHistory.error);
// Display the error message to the user
toastify(transactionHistory.error, "error");
} else {
console.log("Transaction History:", transactionHistory.data);
}
} catch (error) {
console.error("Unexpected error:", error.message);
// Display a fallback error message
toastify("Failed to fetch transaction history. Please try again.", "error");
}

Example Response

Success Response:

{
"success": true,
"data": {
"transactionHistory": [
{
"account": "0x670eebd1efdf8d576e1fe554f3d8e905f28cc5a9",
"amount": "50",
"rawAmount": "50000000",
"blockNumber": "16559058",
"blockTimestamp": "1736234581",
"depositId": "1099511627894",
"id": "0xd001b4809cca945ba80c77bf4b98915c637f3a9f8ccba6dfa363d9bb21d81a2c01000000",
"transactionHash": "0xd001b4809cca945ba80c77bf4b98915c637f3a9f8ccba6dfa363d9bb21d81a2c",
"withdrawalFee": "0",
"txnType": "Liquidity Removed"
}
]
}
}

Error Response:

{
"success": false,
"error": "Address not found"
}