New answers tagged

0 votes

How to encode string as bytes array?

Supposing your string comes from an external source (someone outside your contract calls the function with such string as a parameter) you can cast it to bytes and then slice the bytes into an array. ...
user avatar
1 vote
Accepted

Encode a struct with solidity

If you just want to store this on your contract, solidity structs are already stored encoded in storage. Just define a data member as struct and assign values, it will be properly encoded. In case you ...
user avatar
  • 1,166
0 votes

How to pass bytes parameter to contract method call using Web3.js?

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.
user avatar
  • 1,166
0 votes

Convert/cast an address to uint256

Solution: uint256(uint160(xAddr))
user avatar
  • 265
2 votes
Accepted

Convert bytes to hexadecimal string in solidity

If I understand correctly by "parsing" you mean going from an integer representation (i.e., bytes4 data = 0xa22cb465;) to a string representation in hexadecimal (i.e., string memory test = &...
user avatar
  • 4,899
0 votes

Convert bytes to hexadecimal string in solidity

to convert from bytes to string simply do the following: bytes data = 0xa22cb465; string test = string(data); The value 0xa22cb465 is not a UTF-8 character, so you'll get an error when attempting to ...
user avatar

Top 50 recent answers are included