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
1answer
15 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 = ...
0
votes
1answer
16 views

Is it possible to store an array of bytes (so something like bytes[])?

Edit The original question below seems to work as expected. The issue happens with the call return data is empty. When the response is nothing, the code below fails. The following works, but is ...
0
votes
1answer
32 views

Proper way to save a public key as bytes in a contract

I need to save public keys in many contracts. Despite that this choice costs, I store them as bytes (I know that the best way is to split the key and store it to different bytes32 constants, but that ...
0
votes
0answers
15 views

What is an efficient way for converting 'bytes4' into 'bytes' or 'byte[4]'?

I am currently converting bytes4 into bytes like this: function convert(bytes4 x) public { bytes memory y = abi.encodeWithSelector(x); ... } Is there a more efficient way? Also, is there an ...
0
votes
1answer
58 views

web3 - web3.utils.toHex zeros length

I'm trying to send 12 integer as bytes to a contract function. If I use web3.utils.toHex(12) the variable will become 0xc The problem is that when contract function parses bytes, it reads uint256, ...
0
votes
1answer
28 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[]...
0
votes
0answers
29 views

web3.utils.toHex but combined, hex concat?

I'm currently working with bytes in Remix. The goal I wanted to achieve was to put variables into bytes in one function, copy bytes, paste bytes to another function as a parameter and unpack these ...
1
vote
2answers
38 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 ...
0
votes
1answer
43 views

Remix - Pass bytesX to function

Using Remix, I can't pass a set of bytes ["0xee", "0xff", "0xgg", "0xhh", "0xii"] to my function function foo(bytes5 input) { // Do something } I've already tried all these formats: ["0xee", "...
1
vote
1answer
112 views

Solidity: Convert from “bytes memory” to “address”

I'm using solidity 0.5.0 and when i try to compile my contract it's giving me this error Explicit type conversion not allowed from "bytes memory" to "address" my code is this: /// @dev get broker ...
0
votes
1answer
80 views

Solidity, problem with bytes decoding

back with another question towards solidity Guru's. I am trying to call a method which takes bytes array as an input, but either I am encoding this parameter wrongly or decoding it wrongly. Solidity ...
4
votes
2answers
628 views

Solidity! Invalid implicit conversion from string memory to bytes memory requested

pragma solidity ^0.5 contract ProofOfExistence { // ... some code here function proofFor(string memory document) public view returns(bytes32) { return sha256(document); } //...
0
votes
1answer
122 views

How to set byte in fixed-size byte array?

function computePairId(bytes20 base, bytes20 quote) public view returns (bytes4) { bytes32 pairHash = sha256(abi.encodePacked(base ^ quote)); bytes4 pairId; pairId[0] = pairHash[28]; ...
1
vote
1answer
45 views

Read more than 32 bytes from memory (Assembly)

Assume I am passing a variable bytes (memory) to a function. This variable corresponds to A concatenated with B where A is of size 32 and B is 96 bytes, how can I return A (bytes32) and B (bytes). ...
0
votes
1answer
32 views

How to get the last n bytes of a bytes32 in assembly?

I have the following code: function getBytes5() public returns (bytes5) { uint256 x = now; bytes memory inBytes = new bytes(32); bytes5 outBytes5; assembly { mstore(...
1
vote
1answer
632 views

How to compare two bytes32?

I was using strings before I read that using bytes is gas cheaper. Now I changed my strings to bytes32 but I don't know how to compare them. I need to check if two bytes32 are equal in the require ...
2
votes
2answers
24 views

Validate bytes16 argument size

I have a function which accepts one bytes16 argument. function start( bytes16 reference ) I have some events which I use to track behaviour, using reference as the index. Everything works ...
0
votes
1answer
55 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 ...
1
vote
1answer
462 views

How to convert bytes32 to uint8 in solidity ^0.5.0?

I can see that conversions from bytes to uint used to be much easier in previous versions of solidity. Now, using the same syntax, I get this error: TypeError: Explicit type conversion not allowed ...
2
votes
1answer
482 views

How to check if bytes variable is empty?

I have a mapping in my smart contract with bytes32 keys and bytes values. How can I check if bytes value exists for specific key? Mapping is something like this: mapping(bytes32 => bytes) public ...
4
votes
3answers
1k views

Converting from bytes in 0.5.x?

I'd like to convert bytes into any other type. I.e. "0x57D80C61128d608857d5310BB514223Bb6011CAB" into the address 0x57D80C61128d608857d5310BB514223Bb6011CAB, "5" into the uint256 5 and so on. I have ...
1
vote
0answers
400 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: // ...
1
vote
1answer
114 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 ...
1
vote
1answer
79 views

Bit manipulation (python vs solidity)

I am working on translating code from Python to Solidity and everything has worked up until this last loop. Cannot figure out where the difference is in the code (besides the bytes being in decimal ...
0
votes
1answer
150 views

Is there any way to return multiple structs (or the fields from them) in Solidity when one of the struct fields is of type `bytes`?

I would like to return structs keys from my contract to display on the frontend, ideally 10 at a time. I understand that if I make keyByOwner public I can return a single key at a time with the getter ...
3
votes
1answer
126 views

Bytes variables are connected

Why are these variables confounding? The returned result shows that both loops are effecting both bytes variables (second returns the same result). function mix() public returns (bytes) { ...
0
votes
0answers
40 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 ...
1
vote
1answer
722 views

Is it safe to use abi.encodePacked in production solidity code?

In my solidity game project, I am using this: if (king == keccak256(abi.encodePacked(player)){ //continue as king } else{ // not king } Where player data type is bytes and king is a player ...
6
votes
1answer
110 views

Why is the returndata of a function returning bytes formatted in a weird way?

Solidity 0.4.25. Consider this code contract A{ function test() public view returns (bytes){ bytes memory output = abi.encodePacked(bytes32(1)); return output; } } The ...
1
vote
1answer
110 views

Cant pass a byte into a function without an error

The code below compiles perfectly and seems to work, however when I try to call addTask like: "item1", 1, "i1", 1 I have tried every possible variation of quotes parenthesis, brackets... ...
1
vote
1answer
295 views

Assembly opcodes

I need some help understanding assembly functions pragma solidity ^0.4.23; contract Test { function addTest() public pure returns (uint c) { bytes memory b = new bytes(1024); assembly { c:...
3
votes
1answer
45 views

Representing biometric data with solidity variables — bytes 32 perhaps? [closed]

would like to know which variable type comes closest to representing biometric binary data? Assuming computing storage and power grows exponentially and network latency can be further reduced, would ...
2
votes
1answer
50 views

How to extract int128 from msg.data as first argument?

Let's say we have Ethereum smart contract with fallback function: event onDeposit(int128 indexed key, address from, uint amount); ... function () payable public { require(msg.value > 0); ...
0
votes
1answer
244 views

Solidity: msg.data vs bytes

This is a simple contract that has a function input_data(bytes data) and a simple fallback function that passes msg.data to function input_data. contract test_input_data{ address owner; event ...
2
votes
1answer
344 views

Make character count, count emoji's as 2

I have the following function: function getCharacterCount(string str) constant returns (uint length) { uint i=0; bytes memory string_rep = bytes(str); while (i<string_rep.length) {...
0
votes
1answer
156 views

How to save a number as bytes16 in a smart contract and retrieve the number in javascript?

I have the following smart contract to clarify the issue. pragma solidity ^0.4.17; contract Test { bytes16 number; function getNumber() public view returns(bytes16) { return number; ...
2
votes
1answer
275 views

Optional Multi-Parameter Call to External Contract

I would like to half implement ERC223 for business reasons. This means being able to notify other contracts when they receive tokens, but not revert if the recipient is a contract that doesn't ...
1
vote
1answer
49 views

Pushing bytes to EVM stack

I am sorry if this question seems to be somewhat bad, but I am trying to work out the stack representation of the following opcodes: PUSH1 60 PUSH2 40 would the stack representation of this be: [...
1
vote
2answers
448 views

How to declare a fix bytes type more than bytes32?

I am facing "UnimplementedFeatureError: Nested dynamic arrays not implemented here. " when I try to emit an event contains bytes [] data; I have a fix size of data which is 65bytes but there is no ...
1
vote
1answer
386 views

what is the size of the web3.eth.sign() result?

I am looking for a solution to emit a dynamique array of signature using event. I thought that signature is a byte32 and it works, but I think is a 65 bytes. so what is the exact size and how could ...
0
votes
1answer
172 views

How to extract n bytes from a bytes data?

I want to exract n bytes from a given bytes data. //this function extract the first uint8 from a byte data function extractSelector (bytes data) public constant returns (uint8) { uint8 sel =...
0
votes
1answer
229 views

How to concat different parameters type in one parameter (bytes) and extract them?

I have a function that take 3 parameters function askForHelp (string id, uint256 times, bytes32 signature) { //do something } I want to change it to: function askForHelp(bytes data) { string ...
2
votes
1answer
120 views

How much data can be stored in a bytes type in a smart contract?

What are some estimates of how much data can be stored in a bytes type in a smart contract? contract test { bytes data; function storeData(bytes _data) { data = _data; } }
5
votes
3answers
2k views

How to convert bytes to uint in Solidity

Hey is there a way to convert bytes to uint in Solidity?
0
votes
2answers
41 views

What is the purpose of the variable “maxlength” in this function?

I am trying to understand the function "appendUintToString" from Solidity concatenate uint into a string? The function is recreated below. For now, I am trying to understand what the integer "...
0
votes
0answers
195 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 ...
2
votes
1answer
295 views

How does solidity find positions within a bytes array?

My understanding of arrays is that the initial storage point of the array is used to find the beginning of the array, and finding specific items in the array from that point forward require even ...
0
votes
1answer
327 views

Compare byte32 Keccak256 to the same Keccak256 stored in a byte32 array

I want my function to be able to accept an array of Hashed secrets as a parameter and since solidity doesn't allow for strings, I had to use a byte32[]. The string parameter is an intake for the user'...
1
vote
0answers
332 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 ...
0
votes
1answer
298 views

Understanding Bytes16 Representation in Solidity

I have a simple function printing byte a byte the value of a bytes16 0x20010db8000000000000000000000001 and I get the following result. ['0x20', '0x01', '0x0d', '0xb7', '0xff', '0xff', '0xff', '0x65' ...