[SOLVED] Parse Transaction Logs from OrdersMatched function

How can I parse / decode this log event to receive the same representation as shown on etherscan?

I know I have to convert / parse the hex values somehow, but I dont know how and can not find any source for reading that up.

Here is was I coded up from researching but this throws an invalid argument error
β€œvalue out of range (argument=β€œvalue”, value=20, code=INVALID_ARGUMENT, version=bytes/5.5.0)”

Moralis.Cloud.define("parseNFTLogs", async request => {
  const transaction_hash = request.params.transaction_hash;
  const receipt = await web3.eth.getTransactionReceipt(transaction_hash);

  const ordersMatchedEvent = receipt.logs.filter(
    log => log.topics[0] === ORDERS_MATCHED_EVENT
  )[0];

  let decoded = web3.eth.abi.decodeLog(
    [
      {
        indexed: false,
        name: "buyHash",
        type: "bytes32"
      },
      {
        indexed: false,
        name: "sellHash",
        type: "bytes32"
      },
      {
        indexed: true,
        name: "maker",
        type: "address"
      },
      {
        indexed: true,
        name: "taker",
        type: "address"
      },

      {
        indexed: false,
        name: "price",
        type: "uint256"
      },
      {
        indexed: true,
        name: "metadata",
        type: "bytes32"
      }
    ],
    ordersMatchedEvent.data,
    ordersMatchedEvent.topics
  );

  return decoded;
});

solved it. In case anyone stumbles across the same issues or wants to to the same. You have to remove topic[0] if it is a non anonymous event like in this case.

1 Like