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
0 votes
0 answers
20 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
123 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
61 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
84 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
126 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
32 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
22 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
29 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
9 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
64 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
593 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
105 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
360 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
833 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
207 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
  • 675
0 votes
1 answer
44 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
  • 675
0 votes
1 answer
118 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,492
0 votes
1 answer
50 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
64 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
925 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
74 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
1k 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
83 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
46 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
1 vote
1 answer
591 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
282 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
128 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
66 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
533 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
167 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
35 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
245 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
47 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
  • 516
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
  • 437
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
536 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,064
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
  • 675
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
  • 675
2 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
4 votes
4 answers
4k 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
  • 317
1 vote
1 answer
436 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
509 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
386 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,144
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
738 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
0 votes
1 answer
3k views

How to send bytes data to contract with web3.py to decode

I'm doing a test and trying to send bytes data to a contract so it can parse, store in variables, and return a value. Solidity code pragma solidity 0.6.12; contract testbyte { function sendBytes(...
dekubaka's user avatar
0 votes
1 answer
118 views

Store addresses in bytes variable

I need help with storing a bytes value. contract StoreBytes { bytes public addresses; function addMe() external { // TODO Add msg.sender to addresses. } } What I want is that msg....
dkb's user avatar
  • 683
0 votes
1 answer
58 views

Requiring a bytes32 mapping to be empty, why does my transaction fail?

I have a contract here: contract source code It's a simple one that allows users to create new key:value mappings with bytes32 variables, as well as update the value of a key given that: the key is ...
oi_geeza's user avatar