Questions tagged [bytes]

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

40 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4 votes
0 answers
2k views

Call method with bytes argument from Truffle

When calling a Smart Contract method that requires a bytes parameter, truffle is not accepting the bytes parameter, no matter how I express it. All these tests fail on truffle: // ...
Juan Ignacio Pérez Sacristán's user avatar
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
3 votes
0 answers
765 views

When is it appropriate to use "bytes" (or bytes1 - bytes32) in Solidity?

Upon reviewing prior questions and answers, I understand that "bytes" should be used for raw byte data of arbitrary length and "string" for UTF-8 data of arbitrary length. I also understand that if I ...
CreatedAMadman's user avatar
3 votes
0 answers
258 views

Checking if an address is encoded on the end of a bytes array

I have a bytes array. Within the last 20 bytes, there is an address stored. I am trying to compare the address at the end of this array to the address of a msg.sender, and am wondering if there is a ...
Nate Rush's user avatar
  • 770
2 votes
0 answers
180 views

Performing a C-like pointer increment in Solidity

I have a memory or calldata struct with an attribute of type byte[]. I want to have a memory variable with that data, except for the first n Bytes. In C, you'd just write typename variablename = ...
UTF-8's user avatar
  • 518
2 votes
0 answers
836 views

How to input byte array to a function?

I have a function in my contract and it have bytes1[4] array parameter and returns. function foo(bytes1[4] memory _mdata) public pure returns(bytes1[4]){ bytes1[4] memory result; uint8 i; ...
Kronos's user avatar
  • 896
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
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
1 vote
0 answers
191 views

Why We use hex'ff' for genrate the pair address in uniswapV2 library?

I am working on uniswap router contract for _addLiquadity and there uniswap used uniswapV2library and into that library this below function is return the pair address but i dont understand what first ...
Akash Yadav's user avatar
1 vote
0 answers
445 views

Escaping HTML special characters in Solidity

I realize I am not supposed to do this, and yet I am curious about the least-bad approach. Will the code below work? It is based on some of Uniswap's code. function escapeHTML(string memory input) ...
Tom's user avatar
  • 133
1 vote
1 answer
115 views

Encode String to byte[] to invoke method via web3j

I have a method in a contract that receives a bytes object. Web3J generated code in Java translates it to a byte[] object as parameters. I have the correct String "0x....." thet represents ...
Andrean's user avatar
  • 111
1 vote
0 answers
446 views

How to measure Solidity variables size?

After reading different smart contracts from Uniswap teams and others, I understand that they stricly optimize the data to be stored on-chain, but how can they know what is the minimum size needed for ...
Rougefroid033's user avatar
1 vote
0 answers
18 views

Check string similarity percentage

How can I efficiently check the similarity of two strings? Or better yet, if I have an array of strings, I want to check that the given string is less than e.g. 80 % similar to any of the other ...
user2340939's user avatar
1 vote
2 answers
667 views

How to convert string to bytes256 or arbitrary bytes?

I already know how to convert bytes32ToString and stringToBytes32: function bytes32ToString(bytes32 x) public pure returns (string memory) { bytes memory ...
Lou Treaser's user avatar
1 vote
1 answer
288 views

Byte32 error, even after converting string to hex

I looked everywhere for people with similar problems, but I couldn't find anything. I am confused why I keep getting this error (yes, I know others have had this error too, but not for the same ...
newFinancier's user avatar
1 vote
1 answer
151 views

bytes seem to be limited to length 8

I'm pretty new to Solidity, and I was writing a contract to play around with dynamic arrays. My array length grows, but it seems to stop at length 8. Here's the contract I wrote: pragma solidity 0.4....
Breedly's user avatar
  • 111
1 vote
0 answers
241 views

Convert an hexadecimal string to bytes in pure Solidity

I am using Oraclize to recover a signature from a website. When I have it, I have to check if the address who signed it is correct. To do that, I would use ECRecovery from Zeppelin. The signature ...
Sullof's user avatar
  • 11
1 vote
1 answer
2k views

Solidity Bytes Comparison

I was going through the Create Your Own CryptoCurrency documentation and got stuck at the proofOfWork section. In this, they try to do a check i.e. require(n >= bytes(difficulty)) //Check if its ...
farhankhwaja'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
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
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
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
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

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
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
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
0 votes
1 answer
125 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
  • 703
0 votes
1 answer
119 views

What is the most gas-efficient way to hard-code a bytes array?

I need to hardcode some multi-Kb bytes into my smart contract. So far, the best way I have found to do this is to use abi.encodePacked... return abi.encodePacked( abi.encodePacked( ...
Zane Claes's user avatar
0 votes
1 answer
44 views

String to Bytes Converts to Incorrect Value

I have a string array stored in memory as https://cloudflare-ipfs.com/ipfs/QmSXDsFeNaPa3CJKmn8WKBnA421Zv5r3Ra8n71LZhvEi9s This should convert to ...
Nat's user avatar
  • 279
0 votes
0 answers
304 views

Passing a hash value to function

I'm trying to authenticate users by comparing the hashes created by backend server and contract. Seems like "byte32" values cannot be coerced into strings. So, instead I'm converting it into ...
Vishnu Prakash's user avatar
0 votes
1 answer
153 views

Can I call a contract function in the "data" element via web3, especially when I am using conversion to bytes?

In other words, say In Python I have something like that: signed_txn = w3.eth.account.signTransaction(dict( nonce=w3.eth.getTransactionCount('0x0000000000000000000000000000000'), gasPrice = ...
Robert Ggg's user avatar
0 votes
1 answer
162 views

Combine BytesX and BytesY to create BytesZ?

I am working on a Solidity Smart Contract (^0.5.10) where I want to return an array of Ratings elements. struct Ratings { address restaurant uint8 score }; Since returning Rating[], string[]...
3mrsh's user avatar
  • 93
0 votes
1 answer
318 views

encoding several variables into a byte

I want to define a byte256 and I want to assign different sections of the byte to different variables, any literature or guidance is appreciated. for further clarity I want to do something like ...
Lucas Rodriguez Benitez's user avatar
0 votes
0 answers
109 views

How strings are stored in Solidity on a low level?

So, the question is in the title, let me describe scenario: I make raw rpc call via method eth_call to contract Token to a function name to get token name of type string. Below is my original ...
Roman Frolov's user avatar
  • 3,167
0 votes
0 answers
509 views

Why are elements in a byte array padded to 32 bytes?

On readthedocs.io, it says that byte[] or bytes1[] elements are padded to 32 bytes. I thought at first it was for even distribution, but distribution would still be even if each element had exactly ...
CreatedAMadman's user avatar
0 votes
0 answers
239 views

Dynamically-sized byte array is value type?

In the doc, it says bytes: Dynamically-sized byte array, see Arrays. Not a value-type! string: Dynamically-sized UTF-8-encoded string, see Arrays. Not a value-type! Not a value-type! If ...
bbusdriver's user avatar
  • 1,114