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
33 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
76 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
36 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 ...
3
votes
2answers
294 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
72 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
43 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
30 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(...
0
votes
1answer
356 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
22 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
40 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
322 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
295 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
273 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
96 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
75 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
97 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
87 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
34 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
478 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
82 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
77 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... ...
0
votes
0answers
41 views

Deserialising bytes to a solidity struct

Say I have a struct like struct AppState { address player1; address player2; uint256 winner; uint256[100] board; uint256 move; } Now I have a function which receives a byte ...
1
vote
1answer
220 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
36 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
43 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
191 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
316 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
140 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
225 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
42 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
389 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
308 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
119 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
207 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
106 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; } }
4
votes
2answers
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
33 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
175 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
242 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
286 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
309 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
254 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' ...
0
votes
1answer
191 views

Im using Oraclize to get a random number but the N of bytes confuses me

It seems like when I give the Oraclize query a N of 4, it always returns a 19 digit number, this might be a coincidence but I think not. What if I actually want a number between lets say 0 and 10 * 10^...
0
votes
1answer
240 views

Check bytes32 exists in bytes32[]

I would like to know if this is possible to check in a simple way if a bytes32 value exists in an array of bytes32 value please? contract Test { struct TestStruct { string name; ...
0
votes
0answers
82 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 ...
0
votes
2answers
970 views

How to store hash of an Excel file in Blockchain? [closed]

I'm sorry if this question does not seem to be logic. I want to store hash of an Excel file in Blockchain by following function : //byte fileHash; event LogsetFileHash(byte _hashValue); ...
1
vote
1answer
555 views

Solidity assembly question - mstore

I was searching on how to convert a uint to bytes in Solidity and found this answer. function toBytes(uint256 x) returns (bytes b) { b = new bytes(32); assembly { mstore(add(b, 32), x) } } ...
2
votes
0answers
287 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; ...
0
votes
1answer
221 views

Store literal bytes4 as string

Does anyone have the 'somefunc' below to store bytes (specifically bytes4) as a string? Ideally something to get method_s in the code below: contract Test{ bytes4 public method; string public ...