Questions tagged [bytes]

both the fixed-size array byte, bytes1...bytes32, and the dynamic array bytes types in Solidity

Filter by
Sorted by
Tagged with
1 vote
1 answer
137 views

Grab first 20 bytes of 32-bytes input

In solidity casting or assembly, how do I grab the first 20 bytes of this 32-bytes input: 0x00010000c900c90062fceaad00000000000000000002af416812f9bb6f2fdff5? Thanks!
dNyrM's user avatar
  • 713
0 votes
1 answer
42 views

Solidity: How to decode / trace / search custom error byte code

I ran into this Custom Error during my Foundry test: [FAIL. Reason: Custom Error cd786059:(0xF628...)] and I had no idea about what it means... then I figured out where it went wrong after tracing ...
Russo's user avatar
  • 1,764
1 vote
1 answer
93 views

How to decode a bytes value from Ethereum event with ethers.js

I've got the following event declaration in my Solidity contract: event RemoteOrderCreated(bytes32 indexed id, uint32 indexed nonce, address indexed sender, bytes input); And I capture the event ...
Milkncookiez's user avatar
0 votes
0 answers
33 views

Why "It's better to use the bytes type instead of the bytes1[] type"? Solidity

I read a Note in documentation of Solidity: The type bytes1[] is an array of bytes, but due to padding rules, it wastes 31 bytes of space for each element (except in storage). It is better to use the ...
Trong-Hieu Nguyen's user avatar
0 votes
0 answers
246 views

Uniswap v3: How do I get the path bytes from solidity from array function parameters?

I am trying to write a smart contract that can facilitate multihop swaps. It is important that I am able to pass in 2 arrays into the swap function: an address[] of the tokens and uint256[] of the ...
Ethan's user avatar
  • 1
0 votes
1 answer
97 views

Simple contract fails to deploy to Sepolia

I am trying to deploy a very simple contract to Sepolia. Here is the code: pragma solidity ^0.8.18; contract Object { bytes32 private UID; bytes private Desc; constructor(...
Philip Rutovitz's user avatar
0 votes
1 answer
157 views

How to encode arbitrary amount of parameters for encodeWithSignature without adding them to function definition?

Lets says we have Contract A that needs to call Contract B at a certain address which the requirements that Contract A doesn't know the exact parameter structure the function in that Contract B needs &...
CoderMan's user avatar
0 votes
0 answers
167 views

Calculate the contract address created using create2 with dynamic byte string as a salt

EIP-1014 describes salt as bytes32. However, the function create2 written in assembly allows passing byte string of arbitrary size as the salt parameter. Example function deploy(bytes memory bytecode, ...
Ivan Zakharov's user avatar
0 votes
1 answer
76 views

Chainlink Functions return an array or list of strings from Functions-request-source.js

Hope someone can help. I am stuck trying to work out how best to extract the different string values from the returned bytes data. Chainlink Function request source requires the return value to be a ...
Vince Reid's user avatar
0 votes
1 answer
29 views

Unintentional extra arguments on calldata

I manually inserted 2 32 bytes arguments to a function flipSwitch(bytes memory someData) whose function identifier happens to be 0x30c13ade. My manual arguments: ...
IBeFrogs's user avatar
0 votes
1 answer
30 views

mapping not showing any value corresponding to string key(converted from bytes32)

I have bytes32 data which needs to be converted into a string, then use to get value from mapping(string => string) Trying to convert bytes32 to string using : string(abi.encodePacked(temp)) It is ...
Harman Singh's user avatar
0 votes
0 answers
13 views

Expected Primary Expression error on signature function

With this isValidSignature function: // NOTE: This method not safe, contract may attack by signature replay. /** * Verify if the signer has a valid signature as claimed * @param signer ...
AAMCODE's user avatar
  • 133
2 votes
4 answers
85 views

How to batch list into a single bytes object?

Let's say I have a string list of parameters ["Example String", "vitalikbuterin", "1000"] How can I encode this list into a bytes object, and then decode the bytes to get ...
MuellerSachs's user avatar
1 vote
1 answer
29 views

Can someone explain to me how returns work under the hood in solidity?

Can someone explain how I will be successfully able to return this function reddish(uint256 _red) public view returns (bytes memory) { bytes memory err = abi.encode(msg.sender, _red); assembly ...
Malik Aremu's user avatar
3 votes
2 answers
771 views

How to convert `bytes4` to `bytes memory` in Solidity?

bytes4 is a commonly needed data type in Solidity, due to its use in msg.sig and, more broadly speaking, in function selectors (e.g. Contract.func.selector). How can one convert bytes4 to bytes memory?...
Paul Razvan Berg's user avatar
1 vote
1 answer
122 views

How exactly does the 'hex' prefix work for bytes?

I found some code snippets using the 'hex' prefix before a string in a bytes variable. I can't seem to find its description in the solidity docs. bytes memory bytesVar = "0x01"; bytes ...
Yan Digilov's user avatar
0 votes
1 answer
479 views

Encode Struct[] in ethers to pass to a dynamic bytes

I have a method in solidity: function getVotesWithParams( address account, uint256 blockNumber, bytes memory params ) public view virtual override returns (uint256) { return _getVotes(...
Ritzy Dev's user avatar
  • 271
1 vote
1 answer
1k views

How to decode `encodePacked` data

I have two addresses, _token1 and _token2. I would like to pack them into bytes data to pass it to a function. bytes memory params = abi.encode(_token1, _token2); The obtained params is the ...
ywat's user avatar
  • 177
0 votes
2 answers
277 views

Convert bytes20 to address in assembly

Can you convert a bytes20 to address in assembly (not solidity-typecasting)? If so, how?
dNyrM's user avatar
  • 713
0 votes
1 answer
55 views

Grab the last 32 bytes of 64-bytes input

In assembly, how do I grab the last 32 bytes in a 64-bytes input? I know that this code is for grabbing the first 32: bytes32 half; assembly { half := mload(add(accData2, 32)) }
dNyrM's user avatar
  • 713
0 votes
1 answer
147 views

TypeError: Member "encodeCall" not found or not visible after argument-dependent lookup in abi

I am trying to test abi.encodeCall on Remix. I have this function function getTestData() external pure returns (bytes memory){ // passing empty args () return abi.encodeCall(TargetContract.send,()); } ...
Yilmaz's user avatar
  • 1,540
0 votes
1 answer
51 views

How to pass bytes4 to mapping?

I'm trying to pass bytes4 type to mapping but all I have got is an error saying: **ParserError: Expected identifier but got '='** bytes4 example = 0x11030330; mapping(bytes4 => address) facets; ...
obsessed's user avatar
1 vote
0 answers
67 views

How to handle both String and Bytes return types in Rust

I'm trying to query the MAKER ERC20 contract and get the name and symbol of the token. The problem is that they are stored as a Bytes and I don't want to change the return type of my function from a ...
Mitchs's user avatar
  • 11
1 vote
1 answer
1k views

Unable to deduce common type for array elements in bytes[ ]. Why I am getting this even the first line works perfectly but 2nd one's throws error?

I am trying to get understanding of bytes array but encountered an error where, contract Mytest { > > bytes[] public arr1 = [bytes("happy"), "names"]; // This line ...
Mister_Defender's user avatar
0 votes
2 answers
95 views

bytes5 vs string

I have an smart contract with some defined fixed length variables from 3 to 5 characters long. Defining these variables as string is more intuitive for those that come from another languages. Also ...
pellyadolfo's user avatar
3 votes
2 answers
2k views

How to decode the output of an eth_call that returns a Tuple[]

I am developing a low-level library that interacts with RPC nodes directly. There is a requirement to call the AaveV2 getAllReserveTokens function, and I want to decode the output data. The particular ...
pestopasta's user avatar
2 votes
1 answer
94 views

How to reverse a Solidity bytes sorting?

Suppose I have this bytes pad: 0x0123456789abcdef How can I make it like this: 0xfedcba9876543210 Just by Solidity and not by Assembly.
Alireza's user avatar
  • 533
0 votes
1 answer
51 views

get uint value inside a bytes32 slice

I have the following code: function test_bytes(bytes32 test) external pure returns(bytes3 idx,uint256 idx2) { //test = ...
Jhonatan's user avatar
2 votes
1 answer
688 views

Multiple matching functions error when doing interface.encodeFunctionData

I have openzeppelin's standard ERC721 contract. Below is the helper function that returns bytes data that will be used for some purpose. async function getErc721SafeTransferFromTransaction(...
Haris Nabeel's user avatar
1 vote
1 answer
331 views

Encoding a bytes array with function signature: "TypeError: This type cannot be encoded."

I have a function in a smart contract I'm trying to call with call. function doStuff(bytes[] calldata data) external payable { To call it, I'm running: bytes[] memory dataArray = new bytes[](1); (...
Patrick Collins's user avatar
1 vote
1 answer
135 views

Expected primary expression in byte casting

I have a contract (Implementation.sol) which delegatecalls the other contract (Attacker.sol) to selfdestruct. When I try to compile the Implementation.sol on Remix, I receive Expected primary ...
bic's user avatar
  • 13
0 votes
1 answer
72 views

Parameter function in Solidity

I am a newbie in Solidity. Below is the snippet of code I came across :- pragma solidity ^0.4.0; contract C { //1 function f(uint len) { //...
Brijesh's user avatar
  • 43
0 votes
0 answers
595 views

Issue with abi.decode on output from reverted functions

I am struggling to figure out the abi.decode function when using it to decode the bytes coming as output from a reverted low level call to another contract. The way I am using it is by calling the ...
Pablo González's user avatar
0 votes
1 answer
193 views

abi encoding with selector and additional variable

I am trying to abi encode a function abc(address, string) the encoding looks like this Address.delegateCall(abi.encodeWithSignature("abc(address,string)", _address, _string)) but I actually ...
Adeeb Abdul Salam's user avatar
1 vote
0 answers
36 views

Gas optimization: can I encode an array of different types into hex to pass it to contract call as bytes calldata instead of using memory or storage?

I'd want to have: original types --> encode them in bytes --> string those bytes all together or as an array [[address, address], [uint, uint], [other_type, other_type],...] --> convert to ...
tommy1213's user avatar
1 vote
0 answers
257 views

How to split bytes from calldata and convert into memory variables?

Assume calldata for my smart contract being address as bytes, and few amounts as bytes chained together. How can I extract the bytes for address and store it in address memory address_ = and the ...
tommy1213's user avatar
0 votes
1 answer
87 views

Convert bytes to base 10 number by keeping digits in tact

I have a very weird use case. Tl;dr I'm trying to convert a bytes16 to a base 10 integer by keeping the digits in tact. i.e 0x00000000000000000000000002987391 should become 2987391
BonisTech's user avatar
  • 536
0 votes
0 answers
15 views

Is 1 word 4 bytes or 32 bytes in solidity? [duplicate]

I'm confused about the term word in solidity. When I google word, it says 1 word = 2 bytes but whenever I read word mentioned in the context of solidity, it sounds like 1 word = 32 bytes? What is a ...
xenon's user avatar
  • 447
1 vote
1 answer
1k views

Return bytes from inline assembly

I have two little tests in which I'm trying to return bytes that are populated via inline assembly. It works when I'm using a pre-defined return variable, but I'm getting a buffer overrun when I try ...
Daniel's user avatar
  • 13
0 votes
1 answer
573 views

How to encode string as bytes array?

A similar question has been asked but using web3 in java, however, I would like to encode a string to bytes[] in solidity itself.
MShakeG's user avatar
  • 1,443
3 votes
2 answers
3k views

Encode a struct with solidity

Is it possible to encode a struct in Solidity without serializing each variable separately? Something like: struct MyStruct { uint x; uint y; } MyStruct storage myStruct = MyStruct({ x: 11, ...
dNyrM's user avatar
  • 713
3 votes
1 answer
2k views

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

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 ...
Farzad Z's user avatar
6 votes
1 answer
3k views

Convert/cast an address to uint256

Following these details on the values that make part of the calldata that goes into an L2 message in Arbitrum: https://developer.offchainlabs.com/docs/arbos_formats#l2-messages How do you convert/...
dNyrM's user avatar
  • 713
3 votes
2 answers
4k views

Convert bytes to hexadecimal string in solidity

In a smart contract I have stored a bytes4 value: 0xa22cb465. I'd like to parse this value as a string: string memory test = "0xa22cb465" I've only stumbled upon explanations on how to ...
Riccardo Perego's user avatar
5 votes
4 answers
5k views

Decode multicall bytes[] into readable format?

I created a Uniswap V3 pool using UI. In Transaction multicall(bytes[] data) function was called with this parameter: [0]: 0000000000000000000000000000000000000000000000000000000000000020 [1]: ...
MantasFam's user avatar
  • 327
1 vote
1 answer
462 views

sload. with struct - loading bytes

I'm trying to load varios bytes from a struct in assembly. I found a good explanation here for uint. While this is working for uint and the whole memory slot i cant figure out how to get a bytes1 or ...
beatstorelaxstudy's user avatar
0 votes
1 answer
559 views

How can i change the 5th and 6th byte from bytes8

Hi Guys , How can i change the 5th and 6th byte from this bytes8 0x3FcB875f"0000"ddC4,or just arrive at this solution where: last four bytes(of bytes8) are this way 0x********"0000ddC4&...
Vadim Chilinciuc's user avatar
2 votes
1 answer
416 views

Solidity (find a word in a string and replace it)

I am learning solidity string/byte manipulation and I am trying to create a Solidity function that finds specific words in a string/format and replaces them with given variables to return "edited&...
Sky's user avatar
  • 2,204
1 vote
1 answer
1k views

How does Bytes-Utils slice function work?

I'm quite confused of how the bytes-utils library's slice function. I have a few questions about how it works, especially about the code below. The full code can be found here. Why is tempBytes ...
cpix's user avatar
  • 23
0 votes
1 answer
804 views

EXTCODESIZE returning 32 for contract size less than 32

I'm currently completing the Ethernaut challenges, one of them is to deploy a small contract (runtime bytecode is 10 bytes long). I'm running the tests on my local machine, and using Solidity to ...
riordant's user avatar