1

I'm listening for an event:

OrdersMatched (bytes32 buyHash, bytes32 sellHash, index_topic_1 address maker, index_topic_2 address taker, uint256 price, index_topic_3 bytes32 metadata)

This is what I'm currently doing and I'm getting an error:

contract.on('OrdersMatched', (buyHash, sellHash, from, to, price, metadata) => {
    console.log('from', from)
    console.log('to', to)
    console.log('price', ethers.utils.formatUnits(price, 18)) // decode

    if (metadata !== '0x0000000000000000000000000000000000000000000000000000000000000000') {
      console.log('metadata', ethers.utils.parseBytes32String(metadata)) // decode bytes32 (doesn't work)
    }
    console.log('')
  })

error - uncaughtException: Error: invalid codepoint at offset 3; unexpected continuation byte (argument="bytes", value=Uint8Array(0x5c5321ae45550685308a405827575e3d6b4a84aa), code=INVALID_ARGUMENT, version=strings/5.4.0)

I'd love some help figuring out how to get this decoding.

Thanks!

Edit:

Logs of metadata and its type:

md 0x66fdd5e25ef9ddb305ba3c2aae1856ab9c6f2979000000000000000000000000

md type string

6
  • @MajdTL I updated my post with that info
    – alcatraz
    Oct 13 '21 at 17:44
  • what is the expected value? what should the decoded output looks like :)
    – Majd TL
    Oct 13 '21 at 17:48
  • I don't know. I'm trying to find my project's sales in the OpenSea Shared Contract and was hoping something in the metadata might help
    – alcatraz
    Oct 13 '21 at 17:58
  • okay that makes the question harder, it could mean nothing maybe only a hash or link to something. can you add this please console.log(ethers.utils.isBytesLike(metadata));
    – Majd TL
    Oct 13 '21 at 18:02
  • logs true @MajdTL
    – alcatraz
    Oct 13 '21 at 18:45
0

If the bytes32 is a valid utf8 byte string, then you are using the correct way for decoding:

ethers.utils.parseBytes32String(metadata)

However, not all bytes32 are valid utf8 byte strings (see code points).

In your example 0x66fdd5e25ef9ddb305ba3c2aae1856ab9c6f2979000000000000000000000000, this seems to contain 20 bytes, so I would just guess that this metadata could be an address. I just checked on etherscan, so this indeed is an address.

An address have any of 0 to 255 value in it's bytes, so it can contain invalid code points which are illegal UTF8 characters. That's why your parseBytes32String is triggering an error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.