Here is the code:
async function nftTransfers(){
const userAddress = '0x9ad80abc02ba459d7a7e252b3d173f471daa1012';
const query = new Moralis.Query("EthNFTTransfers");
const pipeline = [
{ match: { from_address: userAddress } },
{ lookup: {
from: "EthTransactions",
let: { hashValue: "$hash" },
pipeline: [
{$match: {$expr: { $eq: ["$transaction_hash", "$$hashValue"]}
}},
{ $project: { gas: 1, value: 1, hash: 1. ,_id :0 }},
],
as: "TokenWithPrice"
}},
{ unwind : "$TokenWithPrice" },
{limit : 100}
];
const result = await query.aggregate(pipeline);
console.log(result)
}
nftTransfers();
Here is the response:
{
from_address: '0x9ad80abc02ba459d7a7e252b3d173f471daa1012',
log_index: 273,
to_address: '0xbb683e735ca23fdb9ba6f22f3608bf5ed20b845f',
token_address: '0xf4ee95274741437636e748ddac70818b4ed7d043',
token_id: '9351',
transaction_hash: '0x79481308e7d78d2ee6a5b4e3eb1e3c2147f3b1c3b11231b0c7fb42fe9b42ffc5',
createdAt: '2022-02-21T12:34:18.908Z',
updatedAt: '2022-02-21T12:34:18.908Z',
amount: '1',
block_hash: '0x5238ddd96256f97398fb2d5eeb696bcd066f0a69eff1c96722b869951e24d442',
block_number: 12857573,
block_timestamp: { __type: 'Date', iso: '2021-07-19T14:30:54.000Z' },
confirmed: true,
contract_type: 'ERC721',
historical: true,
transaction_index: 142,
transaction_type: 'Single',
TokenWithPrice: {
hash: '0x8f2f64b8832ac2e6b4309ee2022a336ed93c299f76ecc0766cecd07881c8c897',
gas: 191664,
value: '17730108140703232'
},
objectId: 'CgRblSR9z8bGVqvSPIsrabmH'
},
{
from_address: '0x9ad80abc02ba459d7a7e252b3d173f471daa1012',
log_index: 273,
to_address: '0xbb683e735ca23fdb9ba6f22f3608bf5ed20b845f',
token_address: '0xf4ee95274741437636e748ddac70818b4ed7d043',
token_id: '9351',
transaction_hash: '0x79481308e7d78d2ee6a5b4e3eb1e3c2147f3b1c3b11231b0c7fb42fe9b42ffc5',
createdAt: '2022-02-21T12:34:18.908Z',
updatedAt: '2022-02-21T12:34:18.908Z',
amount: '1',
block_hash: '0x5238ddd96256f97398fb2d5eeb696bcd066f0a69eff1c96722b869951e24d442',
block_number: 12857573,
block_timestamp: { __type: 'Date', iso: '2021-07-19T14:30:54.000Z' },
confirmed: true,
contract_type: 'ERC721',
historical: true,
transaction_index: 142,
transaction_type: 'Single',
TokenWithPrice: {
hash: '0x62fa9041e91b0ef7d2e92a4c68976e846e801fbd2ba6eb3474a5455b82fd64b8',
gas: 46079,
value: '0'
},
objectId: 'CgRblSR9z8bGVqvSPIsrabmH'
},
Here you will see that Transaction_hash and hash is different in each response
Is my code is correct ? or any thing else you can suggest ?