Skip to main content
All CollectionsWeb3 API
How to Get the First Transaction of a Wallet Address?
How to Get the First Transaction of a Wallet Address?

This article show how to get the first transactions of a wallet address using Moralis API

John Pilla avatar
Written by John Pilla
Updated over a year ago

Sample Code

To get the first transaction of a wallet, you can utilize the Moralis getWalletActiveChains API. Here's a simple example of how to use it:

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");

const runApp = async () => {
await Moralis.start({
apiKey: "YOUR_API_KEY",
});

const address = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045";
const chains = [EvmChain.ETHEREUM];

const response = await Moralis.EvmApi.wallets.getWalletActiveChains({
address,
chains,
});

console.log(response.toJSON());
}

runApp();

The response from the above code will provide details about the first transaction, including the date and block number:

{
"address": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
"active_chains": [
{
"chain": "eth",
"chain_id": "0x1",
"first_transaction": {
"block_timestamp": "2015-09-28T08:24:43.000Z",
"block_number": "302086",
"transaction_hash": "0x9b629147b75dc0b275d478fa34d97c5d4a26926457540b15a5ce871df36c23fd"
},
"last_transaction": {
"block_timestamp": "2023-09-13T04:10:35.000Z",
"block_number": "18124916",
"transaction_hash": "0x03df03fc1dbcb6aac110bd0372412e5f671b93be0b127e730889d826c05d92b4"
}
}
]
}

Use Cases

  1. Getting the Age of the Wallet Address: By retrieving the first transaction's timestamp, you can easily determine the age of a wallet. This can be useful for analytics, trust scoring, or other analytical purposes.

  2. Fetching Initial Transactions: With the block number of the first transaction, you can retrieve a set of subsequent initial transactions of the wallet using getWalletTransactions.

    For instance, to get the early transactions of a wallet using the fromBlock and toBlock values:

const response = await Moralis.EvmApi.transaction.getWalletTransactions({
"chain": EvmChain.ETHEREUM,
"fromBlock": 302086,
"toBlock": 302186,
"address": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
});

This will fetch transactions from block 302086 to 302186, giving you a snapshot of the wallet's early activities and making it easy to retrieve the initial transactions of a wallet without having to paginate through all the transaction data.
โ€‹

Did this answer your question?