Skip to main content

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
1 answer
21 views

How do I call the contract function using ethers.js with bytes parameter, encryptedSecretsUrl? Using Chainlink Functions, sendRequest function

This worked with remix This worked without use of encryptedSecretsUrl using ethers.js. It worked in remix, but it didn't work with ethers.js. provider = new ethers.BrowserProvider(window.ethereum); ...
Pyakhurel Pasas's user avatar
0 votes
0 answers
9 views

I need the solution for Spurious Dragon in constructor arguments in Solidity [duplicate]

I wrote 5 contracts modulating the whole operation of bonds of fixed income. I created #1- the storage of data, #2- the pool of investment with USDC, #3- the contract to issue, redeem and amortization,...
DoctorWeb3's user avatar
0 votes
1 answer
33 views

Invalid type for argument in function call. Invalid implicit conversion from literal_string "" to bytes calldata requested

I'm doing the course of Patrick Collins to learn about programming in Solidity; but some libraries from Chainlink has been changed since 2 years ago. So, when I try to compile the code I have the next ...
Tucan's user avatar
  • 3
0 votes
2 answers
21 views

When should I choose lower-size bytes variables (e.g. bytes23) over bytes32 variables?

I am trying to manage strings on a smart contract. I know these strings will be 46 bytes long so I thought I could convert them into bytes and split them in two bytes32 arrays. Then I realized smaller ...
Pietro D'Amico's user avatar
0 votes
0 answers
48 views

How to generate multi hop swap path with ethers.js?

everyone. I am beginner to blockchain development. Currently I have worked in a web3 project with ethers.js. Now I am going to use Uniswap's multi hop swap. I got SwapRoute instance. But the smart ...
Pavlo Posternak's user avatar
2 votes
1 answer
21 views

Casting different from bit manipulation

Casting between uints and bytes16 yields different results as that of manipulating the bits directly. Why? I thought that with casting we were just changing the representation from bits to bytes, and ...
dNyrM's user avatar
  • 938
1 vote
1 answer
67 views

Manipulate bytes with assembly

Using assembly only, how do I switch, for A0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, the last 20 bytes of the second 32-bytes from the bytes variable below, and keep the rest as it is? Original bytes: ...
dNyrM's user avatar
  • 938
1 vote
0 answers
28 views

Represent UUIDv4 string as bytes16 in event topic

I am trying to emit an Event with UUIDv4 indexed string. Example contract: contract EventEmitter { event ExampleEvent(string indexed id); function dispatchEvent(string memory _uuid) public { ...
Marcin's user avatar
  • 111
1 vote
1 answer
52 views

generate url in smart contract, based on block.chainid and address(this)

For the past few days I have been looking into creating a simple function to generate a url based on block.chainid (uint256) and address(this). The idea is as follows: function url() public view ...
Cloudronaut's user avatar
0 votes
1 answer
69 views

Please Help decode this smart contract code

Today i find this phishing smart contract and i wanna know how he's doing this! There is smart contract and after deploy, fund and call function Start() - funds from contract move to another address ...
Pavlo Konchych's user avatar
0 votes
1 answer
52 views

How to change the offset of calldata value?

Suppose I have a contract below: contract Hack { Switch private target; constructor(address _target) { target = Switch(_target); } function test() external pure returns (...
Shubham's user avatar
  • 25
3 votes
1 answer
171 views

How can we assign bytes to uint256 variables in solidity?

I am confused of this. when I write uint256 internal ownerPrivateKey = 0xB0b; Is this conversion implicit? how are we assigning bytes to a uint256 variable?
Zartaj Afser's user avatar
  • 4,684
2 votes
1 answer
206 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
  • 938
0 votes
1 answer
567 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,804
1 vote
1 answer
720 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
54 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
1 answer
153 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
440 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
1 vote
1 answer
338 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
178 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
47 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
52 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
2 votes
4 answers
203 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
30 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
4 votes
2 answers
1k 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
182 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
775 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
  • 283
3 votes
2 answers
2k 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
  • 217
0 votes
2 answers
438 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
  • 938
1 vote
1 answer
79 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
  • 938
0 votes
1 answer
214 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,705
0 votes
1 answer
59 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
74 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
2 votes
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
155 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
109 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
  • 567
0 votes
1 answer
58 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
914 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
430 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
152 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
74 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
679 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
254 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
40 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
296 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
190 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
  • 672
0 votes
0 answers
16 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
  • 455
2 votes
1 answer
2k 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
  • 23
0 votes
1 answer
656 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,735

1
2 3 4 5