how do I decode an anonymous event?

Viewed 9

I'm trying to decode a simple anonymous event I wrote in my contract and instead of result I'm getting an empty array, does anyone know what I'm doing wrong?

I'm using hardhat.

contract:

pragma solidity ^0.8.9;
contract Lock {

   event DataStored(address admin, uint256 indexed data) anonymous;
   uint256 data;
   function storeData(uint256 data) external {
      data = data;
      emit DataStored(msg.sender, data);

   }
}

deploy.js

const hre = require("hardhat");
const contract = require("../artifacts/contracts/Lock.sol/Lock.json");
const abiDecoder = require('abi-decoder');

async function main() {
  

  const Lock = await hre.ethers.getContractFactory("Lock");
  const lock = await Lock.deploy();

  await lock.deployed();

  console.log(
    ` deployed to ${lock.address}`
  );
  tx = await lock.storeData(10);
  const transactionReceipt = await tx.wait()
  abiDecoder.addABI(contract.abi);
  const decodedLogs = abiDecoder.decodeLogs(transactionReceipt.events);
  console.log(transactionReceipt.events)
  console.log(decodedLogs);


}
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

and the result I'm getting from running the deploy.js

deployed to 0x21dF544947ba3E8b3c32561399E88B52Dc8b2823
[]
0 Answers
Related