2

I'm trying to call a method in a contract and the method is like this:

function myMethod(uint8 tid, bytes calldata _bytes)
    public
    view
    returns (string memory)
{ ... }

I'm using Web3.js to call the methods and I have done successful ones on other methods but I can't find a way to pass bytes data to call this method. I would appreciate it if you could help me.

1 Answer 1

0

bytes is a variable type that holds a sequence of bytes from 1 to up to 32.

Read about it in the docs.

On Web3 you use numberToHex or utf8ToHex for strings.

3
  • I used web3.utils.hexToBytes but didn't work
    – Farzad Z
    May 9, 2022 at 14:42
  • Use hex string 0x..., added to answer. Would help if you stated what type you're trying to send.
    – Kof
    May 9, 2022 at 17:41
  • The first parameter is uint8 which is the token id and the next one is an array of bytes (the bytes type in solidity)
    – Farzad Z
    May 9, 2022 at 20:38

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.