Hello everyone.
Can anybody help me with ABI (https://c2n.me/4hashle.png) for PairCreated / Mint for Ethereum / Bsc Mainnet Moralis Streams.
Thanks.
Hello everyone.
Can anybody help me with ABI (https://c2n.me/4hashle.png) for PairCreated / Mint for Ethereum / Bsc Mainnet Moralis Streams.
Thanks.
do you have an example for a transaction with that event?
I have this one ABI with PairCreated and others events:
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "token0",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "token1",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "pair",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "PairCreated",
"type": "event"
},
{
"constant": true,
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "allPairs",
"outputs": [
{
"internalType": "address",
"name": "pair",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "allPairsLength",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "tokenA",
"type": "address"
},
{
"internalType": "address",
"name": "tokenB",
"type": "address"
}
],
"name": "createPair",
"outputs": [
{
"internalType": "address",
"name": "pair",
"type": "address"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "feeTo",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "feeToSetter",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "tokenA",
"type": "address"
},
{
"internalType": "address",
"name": "tokenB",
"type": "address"
}
],
"name": "getPair",
"outputs": [
{
"internalType": "address",
"name": "pair",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "setFeeTo",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "setFeeToSetter",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]
and this one with Mint:
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount0",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount1",
"type": "uint256"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
}
],
"name": "Burn",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount0",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount1",
"type": "uint256"
}
],
"name": "Mint",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount0In",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount1In",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount0Out",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount1Out",
"type": "uint256"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
}
],
"name": "Swap",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint112",
"name": "reserve0",
"type": "uint112"
},
{
"indexed": false,
"internalType": "uint112",
"name": "reserve1",
"type": "uint112"
}
],
"name": "Sync",
"type": "event"
},
{
"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"
},
{
"constant": true,
"inputs": [],
"name": "DOMAIN_SEPARATOR",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "MINIMUM_LIQUIDITY",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "pure",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "PERMIT_TYPEHASH",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"payable": false,
"stateMutability": "pure",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
}
],
"name": "burn",
"outputs": [
{
"internalType": "uint256",
"name": "amount0",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "amount1",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [
{
"internalType": "uint8",
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "pure",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "factory",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getReserves",
"outputs": [
{
"internalType": "uint112",
"name": "reserve0",
"type": "uint112"
},
{
"internalType": "uint112",
"name": "reserve1",
"type": "uint112"
},
{
"internalType": "uint32",
"name": "blockTimestampLast",
"type": "uint32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
},
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "initialize",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "kLast",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
}
],
"name": "mint",
"outputs": [
{
"internalType": "uint256",
"name": "liquidity",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "pure",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "nonces",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "deadline",
"type": "uint256"
},
{
"internalType": "uint8",
"name": "v",
"type": "uint8"
},
{
"internalType": "bytes32",
"name": "r",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "s",
"type": "bytes32"
}
],
"name": "permit",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "price0CumulativeLast",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "price1CumulativeLast",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
}
],
"name": "skim",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "uint256",
"name": "amount0Out",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "amount1Out",
"type": "uint256"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "swap",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "pure",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "sync",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "token0",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "token1",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]
So question is how I can do proper ABI only for PairCreated / Mint events?
Thanks.
Any tx on Bsc / Eth Mainnets.
you can copy that abi and after you paste it in admin interface you select only the topic that you are interested about
or you can edit the abi to remove the other events before pasting it
That’s why I ask about it ) I have 2 ABI and I need only one ABI with 2 events. That’s all. I don’t know how It can be done.
Thanks.
this is an event example, just copy the events from those two ABIs and create a new abi
Hello.
So I setup Streams and now I have a lot of records. Now I have another question about parsing these records.
For example I have these recods:
{
"confirmed": false,
"chainId": "0x38",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "token0",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "token1",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "pair",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "PairCreated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount0",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount1",
"type": "uint256"
}
],
"name": "Mint",
"type": "event"
}
],
"streamId": "b8293b3c-05ae-4b01-b46d-2daf32afbaa8",
"tag": "bsc mainnet, eth mainnet",
"retries": 0,
"block": {
"number": "23216703",
"hash": "0xab9e79d0aff32e67b3c05a4f59e9438fcf4f4b7b914213eabbb28d485e17c606",
"timestamp": "1668942259"
},
"logs": [
{
"logIndex": "176",
"transactionHash": "0x8959307a1eba91869c622e1951b8deb9ad3ea707f07be6ff409bcd21f778f1e6",
"address": "0x5598f0ebdf70e9c1144c755b9abb4a45d8c19832",
"data": "0x000000000000000000000000000000000000000000000000003caad5b71a299800000000000000000000000000000000000000000000000ee11df32fbe0aae4e",
"topic0": "0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f",
"topic1": "0x00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e",
"topic2": null,
"topic3": null
}
],
"txs": [],
"txsInternal": [],
"erc20Transfers": [],
"erc20Approvals": [],
"nftApprovals": {
"ERC1155": [],
"ERC721": []
},
"nftTransfers": []
}
{
"confirmed": true,
"chainId": "0x38",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "token0",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "token1",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "pair",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "PairCreated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount0",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount1",
"type": "uint256"
}
],
"name": "Mint",
"type": "event"
}
],
"streamId": "b8293b3c-05ae-4b01-b46d-2daf32afbaa8",
"tag": "bsc mainnet, eth mainnet",
"retries": 0,
"block": {
"number": "23216685",
"hash": "0xdd553784947310d9b6a2946f5b6c648a7a2c00db3c751cdb7baaabaa7284675a",
"timestamp": "1668942198"
},
"logs": [
{
"logIndex": "72",
"transactionHash": "0xebc7f27dc35fa98eb2924c56fe9348a427c5412f7ee9abf47c0d9b6144eda511",
"address": "0x800946d29e40199963100d67c9265b1725f80333",
"data": "0x000000000000000000000000000000000000000000000000000000002365de5d0000000000000000000000000000000000000000000000008bd313206943e452",
"topic0": "0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f",
"topic1": "0x00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e",
"topic2": null,
"topic3": null
}
],
"txs": [],
"txsInternal": [],
"erc20Transfers": [],
"erc20Approvals": [],
"nftApprovals": {
"ERC1155": [],
"ERC721": []
},
"nftTransfers": []
}
{
"confirmed": false,
"chainId": "0x38",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "token0",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "token1",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "pair",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "PairCreated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount0",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount1",
"type": "uint256"
}
],
"name": "Mint",
"type": "event"
}
],
"streamId": "b8293b3c-05ae-4b01-b46d-2daf32afbaa8",
"tag": "bsc mainnet, eth mainnet",
"retries": 0,
"block": {
"number": "23216704",
"hash": "0x1d8124b338123cd6c0f635679b41799189f9e35dd8fcfeb56bdce65808b90326",
"timestamp": "1668942262"
},
"logs": [
{
"logIndex": "199",
"transactionHash": "0x5320c0af6b434cac28ec2f22b2467b78e7a6326744f2caf5c78918d8bf52401e",
"address": "0x2315faf6aafe06a06c884d04975059e82be08bf7",
"data": "0x0000000000000000000000000000000000000000000000000078f7e1b4e29ec200000000000000000000000000000000000000000010cd072eca98c27641b29c",
"topic0": "0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f",
"topic1": "0x00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e",
"topic2": null,
"topic3": null
},
{
"logIndex": "277",
"transactionHash": "0x307c614fb23ef68fe593ded5239377461629fc04d78b816e45b0e0993d79e421",
"address": "0x22d954ca5540cab869ada9bd9d339cde3a9313b3",
"data": "0x0000000000000000000000000000000000000000000000000ff3a72d3252e7e900000000000000000000000000000000000000000000000012ad52c02cbe0883",
"topic0": "0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f",
"topic1": "0x0000000000000000000000003a6d8ca21d1cf76f653a67577fa0d27453350dd8",
"topic2": null,
"topic3": null
}
],
"txs": [],
"txsInternal": [],
"erc20Transfers": [],
"erc20Approvals": [],
"nftApprovals": {
"ERC1155": [],
"ERC721": []
},
"nftTransfers": []
}
{
"confirmed": false,
"chainId": "0x1",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "token0",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "token1",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "pair",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "PairCreated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount0",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount1",
"type": "uint256"
}
],
"name": "Mint",
"type": "event"
}
],
"streamId": "b8293b3c-05ae-4b01-b46d-2daf32afbaa8",
"tag": "bsc mainnet, eth mainnet",
"retries": 0,
"block": {
"number": "16010809",
"hash": "0xc0ec9eaed48bc15a37a5cedb81ea6d0d857d819930c449adf80791a8e9c35561",
"timestamp": "1668942263"
},
"logs": [
{
"logIndex": "31",
"transactionHash": "0x645fb789211c510c2b09ff94f7e8f5860489c5efcdc9b5fa9e079bcf27465246",
"address": "0x16b203893eb1894331c177df7e0ccbe5c0cbd599",
"data": "0x00000000000000000000000000000000000000000000000006ee49e1e389093200000000000000000000000000000000000000000000000000110b952f0254b1",
"topic0": "0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f",
"topic1": "0x0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d",
"topic2": null,
"topic3": null
}
],
"txs": [],
"txsInternal": [],
"erc20Transfers": [],
"erc20Approvals": [],
"nftApprovals": {
"ERC1155": [],
"ERC721": []
},
"nftTransfers": []
}
and so on …
How I can understand where is PairCreated or Mint?
Thanks.
in this case, from topic0, this log will be specific to one of those two cases
you can use ethers to parse the logs or the sdk
you can also look in bscscan and see that topic0 to what event corresponds
Yep. Already got it. But thanks )
Can u provide me with more details. Thanks.
Yep. Already got it. But thanks )
something similar to this code
You are my hero!
Thank you so much for your help and attention!
@cryptokid can u help me with this code:
moralis.js
import express from 'express';
import Moralis from 'moralis/node.js';
//import { EvmChain } from '@moralisweb3/evm-utils';
import { sv, empty, addDebugData, ucfirst, writeToLog, getDateTimeDiff } from '../lib/helpers.js';
import oConfig from '../config/index.js';
import fs from 'fs';
import { Console } from 'console';
const oApp = express();
const iPort = 3000;
const Logger = new Console(
{
stdout: fs.createWriteStream('./logs/moralis-streams-access.log', {flags: 'a'}),
stderr: fs.createWriteStream('./logs/moralis-streams-errors.log', {flags: 'a'})
});
async function decodeWithEthers(sABI, sData, arTopics)
{
try
{
const oInterface = new ethers.utils.Interface(sABI);
const {arArgs} = oInterface.parseLog({sData, arTopics});
const oEvent = oInterface.getEvent(arTopics[0]);
const arDecoded = {};
sv({
group: 'decodeWithEthers',
vars: {
sABI: sABI,
sData: sData,
arTopics: arTopics,
oInterface: oInterface,
arArgs: arArgs,
oEvent: oEvent
}
});
oEvent.inputs.forEach((oInput, iIndex) => {
if(oInput.type === 'uint256')
{
arDecoded[oInput.name] = ethers.BigNumber.from(arArgs[iIndex]._hex).toString();
return;
}
if(oInput.type === 'bytes')
{
arDecoded[oInput.name] = arArgs[iIndex].hash;
return;
}
if(oInput.type === 'address')
{
arDecoded[oInput.name] = arArgs[iIndex].toLowerCase();
return;
}
arDecoded[oInput.name] = arArgs[iIndex];
});
return arDecoded;
}
catch(sError)
{
sv({
group: 'decodeWithEthers',
vars: {
sError: sError
}
});
//return {};
}
}
oApp.use(express.json());
oApp.post('/moralis-streams', async (oRequest, oResponse) => {
try
{
const oJson = {"confirmed":false,"chainId":"0x38","abi":[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token0","type":"address"},{"indexed":true,"internalType":"address","name":"token1","type":"address"},{"indexed":false,"internalType":"address","name":"pair","type":"address"},{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"PairCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"Mint","type":"event"}],"streamId":"b8293b3c-05ae-4b01-b46d-2daf32afbaa8","tag":"bsc mainnet, eth mainnet","retries":0,"block":{"number":"23216703","hash":"0xab9e79d0aff32e67b3c05a4f59e9438fcf4f4b7b914213eabbb28d485e17c606","timestamp":"1668942259"},"logs":[{"logIndex":"176","transactionHash":"0x8959307a1eba91869c622e1951b8deb9ad3ea707f07be6ff409bcd21f778f1e6","address":"0x5598f0ebdf70e9c1144c755b9abb4a45d8c19832","data":"0x000000000000000000000000000000000000000000000000003caad5b71a299800000000000000000000000000000000000000000000000ee11df32fbe0aae4e","topic0":"0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f","topic1":"0x00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e","topic2":null,"topic3":null}],"txs":[],"txsInternal":[],"erc20Transfers":[],"erc20Approvals":[],"nftApprovals":{"ERC1155":[],"ERC721":[]},"nftTransfers":[]};
const oRequestBody = oJson; //oRequest.body;
const sTokenNetwork = (!empty(oConfig.services.moralis.chains.streams[oRequestBody.chainId]) ? oConfig.services.moralis.chains.streams[oRequestBody.chainId] : '');
if(sTokenNetwork == 'bscscan.com')
{
//const sTransferType
}
const arDecodedData = await decodeWithEthers(
oConfig.oPancakeSwap.oABI.sDefaultContract, //oRequestBody.abi,
oRequestBody.logs[0].data,
[oRequestBody.logs[0]['topic0'], oRequestBody.logs[0]['topic1'], oRequestBody.logs[0]['topic2'], oRequestBody.logs[0]['topic3']]
);
sv({
group: 'moralis-streams',
vars: {
oRequestBody: oRequestBody,
sTokenNetwork: sTokenNetwork,
abi: oRequestBody.abi,
data: oRequestBody.logs[0].data,
topics: [oRequestBody.logs[0]['topic0'], oRequestBody.logs[0]['topic1'], oRequestBody.logs[0]['topic2'], oRequestBody.logs[0]['topic3']],
arDecodedData: arDecodedData
}
});
}
catch(oError)
{
console.error(oError);
}
});
oApp.listen(iPort, () => {
console.log(`Moralis streams app listening on port ${iPort}`);
});
Where is oJson - answer from Moralis Streams.
Where is oConfig.oPancakeSwap.oABI.sDefaultContract:
[
{
"inputs": [
{
"internalType": "address",
"name": "_feeToSetter",
"type": "address"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "token0",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "token1",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "pair",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "PairCreated",
"type": "event"
},
{
"constant": true,
"inputs": [],
"name": "INIT_CODE_PAIR_HASH",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "allPairs",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "allPairsLength",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "tokenA",
"type": "address"
},
{
"internalType": "address",
"name": "tokenB",
"type": "address"
}
],
"name": "createPair",
"outputs": [
{
"internalType": "address",
"name": "pair",
"type": "address"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "feeTo",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "feeToSetter",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
},
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "getPair",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "_feeTo",
"type": "address"
}
],
"name": "setFeeTo",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "_feeToSetter",
"type": "address"
}
],
"name": "setFeeToSetter",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]
and I have this answer:
decodeWithEthers
sError
moralis-streams
oRequestBody
confirmed: false
chainId: 0x38
abi
0
anonymous: false
inputs
0
indexed: true
internalType: address
name: token0
type: address
1
indexed: true
internalType: address
name: token1
type: address
2
indexed: false
internalType: address
name: pair
type: address
3
indexed: false
internalType: uint256
name:
type: uint256
name: PairCreated
type: event
1
anonymous: false
inputs
0
indexed: true
internalType: address
name: sender
type: address
1
indexed: false
internalType: uint256
name: amount0
type: uint256
2
indexed: false
internalType: uint256
name: amount1
type: uint256
name: Mint
type: event
streamId: b8293b3c-05ae-4b01-b46d-2daf32afbaa8
tag: bsc mainnet, eth mainnet
retries: 0
block
number: 23216703
hash: 0xab9e79d0aff32e67b3c05a4f59e9438fcf4f4b7b914213eabbb28d485e17c606
timestamp: 1668942259
logs
0
logIndex: 176
transactionHash: 0x8959307a1eba91869c622e1951b8deb9ad3ea707f07be6ff409bcd21f778f1e6
address: 0x5598f0ebdf70e9c1144c755b9abb4a45d8c19832
data: 0x000000000000000000000000000000000000000000000000003caad5b71a299800000000000000000000000000000000000000000000000ee11df32fbe0aae4e
topic0: 0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f
topic1: 0x00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e
topic2: null
topic3: null
txs
txsInternal
erc20Transfers
erc20Approvals
nftApprovals
ERC1155
ERC721
nftTransfers
sTokenNetwork: bscscan.com
abi
0
anonymous: false
inputs
0
indexed: true
internalType: address
name: token0
type: address
1
indexed: true
internalType: address
name: token1
type: address
2
indexed: false
internalType: address
name: pair
type: address
3
indexed: false
internalType: uint256
name:
type: uint256
name: PairCreated
type: event
1
anonymous: false
inputs
0
indexed: true
internalType: address
name: sender
type: address
1
indexed: false
internalType: uint256
name: amount0
type: uint256
2
indexed: false
internalType: uint256
name: amount1
type: uint256
name: Mint
type: event
data: 0x000000000000000000000000000000000000000000000000003caad5b71a299800000000000000000000000000000000000000000000000ee11df32fbe0aae4e
topics
0: 0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f
1: 0x00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e
2: null
3: null
arDecodedData: undefined
So I found that error on:
const oInterface = new ethers.utils.Interface(sABI);
But error is empty (((
And If I comment
//const oInterface = new ethers.utils.Interface(sABI);
//const {arArgs} = oInterface.parseLog({sData, arTopics});
//const oEvent = oInterface.getEvent(arTopics[0]);
//const arDecoded = {};
then I see vars:
sv({
group: 'decodeWithEthers',
vars: {
sABI: sABI,
sData: sData,
arTopics: arTopics
//oInterface: oInterface,
//arArgs: arArgs,
//oEvent: oEvent
}
});
So problem with
const oInterface = new ethers.utils.Interface(sABI);
But wrong with ABI?
Thanks.
try to pass here the abi, the logs, the topics (you can try with one topic first)
you can also hardcode the parameters while testing
the abi seems ok, what you have for logs there? try to pass entire logs[0], not only the logs data
U mean string not var?
Which one?
Wrote above:
logs
0
logIndex: 176
transactionHash: 0x8959307a1eba91869c622e1951b8deb9ad3ea707f07be6ff409bcd21f778f1e6
address: 0x5598f0ebdf70e9c1144c755b9abb4a45d8c19832
data: 0x000000000000000000000000000000000000000000000000003caad5b71a299800000000000000000000000000000000000000000000000ee11df32fbe0aae4e
topic0: 0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f
topic1: 0x00000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e
topic2: null
topic3: null
Thanks.
const arDecodedData = await decodeWithEthers(
oConfig.oPancakeSwap.oABI.sDefaultContract, //oRequestBody.abi,
oRequestBody.logs[0].data,
[oRequestBody.logs[0]['topic0'], oRequestBody.logs[0]['topic1']]
);
changed to:
const arDecodedData = await decodeWithEthers(
[{"inputs":[{"internalType":"address","name":"_feeToSetter","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token0","type":"address"},{"indexed":true,"internalType":"address","name":"token1","type":"address"},{"indexed":false,"internalType":"address","name":"pair","type":"address"},{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"PairCreated","type":"event"},{"constant":true,"inputs":[],"name":"INIT_CODE_PAIR_HASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allPairs","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"allPairsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"}],"name":"createPair","outputs":[{"internalType":"address","name":"pair","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"feeTo","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"feeToSetter","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"getPair","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_feeTo","type":"address"}],"name":"setFeeTo","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_feeToSetter","type":"address"}],"name":"setFeeToSetter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}],
oRequestBody.logs[0].data,
[oRequestBody.logs[0]['topic0'], oRequestBody.logs[0]['topic1']]
);
The same answer:
decodeWithEthers
sError
where is catch block in decodeWithEthers:
catch(sError)
{
sv({
group: 'decodeWithEthers',
vars: {
sError: sError
}
});
//return {};
}
So error still at:
const oInterface = new ethers.utils.Interface(sABI);
((((
there, try without that .data
at the end, it needs full log info, not only the log data
I found the problem )
So right now we have proper code like this:
async decodeWithEthers(sABI, data, topics)
{
try
{
const oInterface = new ethers.utils.Interface(sABI);
const {args} = oInterface.parseLog({ data, topics });
const oEvent = oInterface.getEvent(topics[0]);
const arDecodedData = {};
oEvent.inputs.forEach((oInput, iIndex) => {
if(!empty(oInput.name))
{
if(oInput.type === 'uint256')
{
arDecodedData[oInput.name] = ethers.BigNumber.from(args[iIndex]._hex).toString();
return;
}
if(oInput.type === 'bytes')
{
arDecodedData[oInput.name] = args[iIndex].hash;
return;
}
if(oInput.type === 'address')
{
arDecodedData[oInput.name] = args[iIndex].toLowerCase();
return;
}
arDecodedData[oInput.name] = args[iIndex];
}
});
return arDecodedData;
}
catch(sError)
{
return {};
}
}
and prepare code:
oApp.post('/moralis-streams', async (oRequest, oResponse) => {
let sErrorMsg = null;
try
{
const oRequestBody = oRequest.body;
const sTokenNetwork = (!empty(oConfig.services.moralis.chains.streams[oRequestBody.chainId]) ? oConfig.services.moralis.chains.streams[oRequestBody.chainId] : '');
let sTransferType = null;
let arTopics = [];
let arDecodedData = null;
let oLog = null;
if(sTokenNetwork == 'bscscan.com')
{
for(let i = 0; i < oRequestBody.logs; i++)
{
arTopics = [];
oLog = oRequestBody.logs[i];
if(!empty(oRequestBody.logs[i]['topic0']))
arTopics.push(oRequestBody.logs[i]['topic0']);
if(!empty(oRequestBody.logs[i]['topic1']))
arTopics.push(oRequestBody.logs[i]['topic1']);
if(!empty(oRequestBody.logs[i]['topic2']))
arTopics.push(oRequestBody.logs[i]['topic2']);
if(!empty(oRequestBody.logs[i]['topic3']))
arTopics.push(oRequestBody.logs[i]['topic3']);
arDecodedData = await oLotusMarket.decodeWithEthers(oRequestBody.abi, oRequestBody.logs[i].data, arTopics);
if(!empty(arDecodedData))
{
if(!empty(arDecodedData.pair))
sTransferType = 'PairCreated';
else if(!empty(arDecodedData.sender))
sTransferType = 'Mint';
}
switch(sTransferType)
{
case 'PairCreated':
...
break;
case 'Mint':
...
break;
}
}
}
oResponse.status(200);
oResponse.send();
}
catch(sError)
{
sErrorMsg = `Error parse data from moralis streams:`;
Logger.error(addDebugData(sFileName, sErrorMsg + '\r\n' + sError));
}
});
Perhaps it will be useful for someone.
@cryptokid Thank you for your help and attention.