Reputation: 1
I want to get all new transactions from a specified wallet and Im using this code. It just dont work when I use the function tx["transaction"]["from"]
and I filter the wallet or ca I want on "WALLET"
.
Im using Alchemy methods with ws and I have read the documentation about how to use it, I should be missing something.
const { Alchemy, Network, AlchemySubscription } = require("alchemy-sdk")
const {ethers, FixedNumber} = require("ethers")
const delay = require('delay')
require("dotenv").config()
const ARBI_WS_KEY = process.env.ARBI_WS_KEY
const settings = {
apiKey: ARBI_WS_KEY, // Replace with your Alchemy API Key
network: Network.ARB_MAINNET, // Replace with your network
}
const alchemy = new Alchemy(settings)
// Subscription for Alchemy's minedTransactions API
const add = async () => {
alchemy.ws.on(
{
method: AlchemySubscription.MINED_TRANSACTIONS,
},
(tx) => {
let add0 = String(tx["transaction"]["from"])
if( add0 == "WALLET"){
console.log(tx["transaction"]["hash"])
}
}
)
}
Its weird because everything works when I filter tx["transaction"]["to"]
and I specify a wallet or a contract to filter but when trying to filter "from"
I dont get anything.
Upvotes: 0
Views: 852
Reputation: 49
here is the sample script to get transactions from the chain.
the data need to be filtered accordingly.
const WSSURL_BSC= `Alchemylink`;
const { ethers } = require("ethers");
var provider = ethers.getDefaultProvider(WSSURL_BSC);
provider.on("block", (blockNumber) => {
provider.getBlockWithTransactions(blockNumber).then(block => {
console.log(`Got txns for block ${blockNumber}`);
block.transactions.filter(tx => tx.data == '0x').forEach(tx => {
// raw transactions
});
block.transactions.filter(tx => tx.data != '0x').forEach(tx => {
// token transactions
});
});
});
Upvotes: 0