0

I am calling a solidity function which returns a byte4 value through web3, which returns the current string:

0x15fb397c00000000000000000000000000000000000000000000000000000000 

I need to convert this string to bytes4. Will truncating it be a "safe" way?

3 Answers 3

0

Yup, thats what I do. Just take the first guys and chop off the rest.

0

With Javascript:

const 4ByteCode="0x15fb397c00000000000000000000000000000000000000000000000000000000".slice(0,10) // 0x15fb397c 

it will give bytes 4 , its all safe.

0

each byte is represented as 2 characters so you could use this function:

function parseBytes(data, numberOfBytes) { return data.slice(0, numberOfBytes * 2); } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.