I am looking for an example on how to create a stream that listen to buy and sell transaction for a specific token on a specific dex example listen to buy transaction for the Bard token on uniswap.
you can try it like this
const transferErc20Abi = [
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "from",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "to",
type: "address",
},
{
indexed: false,
internalType: "uint256",
name: "value",
type: "uint256",
},
],
name: "Transfer",
type: "event",
},
];
const options = {
chains: [EvmChain.ETHEREUM],
description: "Token buy or sell", // your description
tag: "buy and sell ", // give it a tag
abi: transferErc20Abi,
includeContractLogs: true,
topic0: ["Transfer(address,address,uint256)"],
advancedOptions: [
{
topic0: "Transfer(address,address,uint256)",
filter: {
or: [
{ eq: ["from", "0x1C8a9844091d5136b50F5B04b30dE9E564ce397b"] },
{ eq: ["to", "0x1C8a9844091d5136b50F5B04b30dE9E564ce397b"] },
],
},
},
],
webhookUrl: "https://YOUR_WEBHOOK_URL", // webhook url to receive events,
};
const stream = await Moralis.Streams.add(options);
const { id } = stream.toJSON(); // { id: 'YOUR_STREAM_ID', ...stream }
// Attach the contract address to the stream
await Moralis.Streams.addAddress({
id,
address: "0xxxxxxxx", // Bard token address
});
I replace Bard adress with the actual contract adress or it is just a constant?
here you should use
{ eq: ["sender", "0x1C8a9844091d5136b50F5B04b30dE9E564ce397b"] }
same here =>
use 0x1C8a9844091d5136b50F5B04b30dE9E564ce397b
Good thanks i will try to work with that.
1 Like
I got invalid filter check.
ive updated the message