How to handle TransactionResultReceipt in getDecodedLogs

As you’ve got the event data (data property on the receipt), and you know the shape of the log, you could instantiate the StructCoder directly. But as @maschad states, the easiest way to do this is via the ABI, then you can just call the ABICoder directly rather than having to manage coders yourself, as documented here.

But heres how I’d expect it to work based off your description:

    const data = arrayify(
      '0x40000000667753a24000000068588722000000000000000b6d796e616d652e7377617900000000000000003e15247411a05edc60391d7410eabc3d0ee2eb5f8b2bd8102b41e7e94b22fbf2'
    );

    const identityCoder = new EnumCoder('Identity', {
      Address: new StructCoder('Address', {
        bits: new B256Coder(),
      }),
      ContractId: new StructCoder('ContractId', {
        bits: new B256Coder(),
      }),
    });

    const buyEventCoder = new StructCoder('BuyEvent', {
      time: new BigNumberCoder('u64'),
      price: new BigNumberCoder('u64'),
      strings: new StdStringCoder(),
      buyer: identityCoder,
      seller: identityCoder,
    });

    const [decoded] = buyEventCoder.decode(data, 0);

However I’m getting some decoding errors so I expect the shape isn’t as we expect. So if you share the ABI, we can can match it to a logId, which will equate to a type which we can then pass to the ABICoder. All the coders and their expected bytes can be found here.

2 Likes