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
22
votes
2answers
14k views

How to pass arbitrary bytes to a function in Remix

According to this question I could write a simple contract like: contract SimpleStorage { bytes input; function setInput(bytes enterBytes){ input = enterBytes; } } Using "0x1234" as a ...
25
votes
4answers
8k views

How to store IPFS hash using bytes?

Following Q/A (What datatype should I use for an IPFS address hash?) recommend us to use bytes to store IPFS hash. I was using following example(https://github.com/AdrianClv/ethereum-ipfs/blob/master/...
12
votes
6answers
8k views

How to convert an address to bytes in Solidity?

What is the recommended way to convert an address to bytes in Solidity?
9
votes
2answers
6k views

How to concatenate a bytes32[] array to a string?

I am passing an array of bytes32 to my function. This array can contain numbers or hashes etc. to identify an object. In a new use case I want to pass a URL to this function by splitting the URL into ...
7
votes
3answers
2k views

How can I split a Bytes32 source into two halfs and store them in Bytes16?

I want to split a 32 Byte source: first half in Bytes16 half1; second half in Bytes16 half2. My code works, however only for dynamic array, not with fixed size 16. pragma solidity ^0.4.8; contract ...
3
votes
1answer
3k views

Solidity convert hex string to bytes

I try to convert hex string to bytes. function MyContract() public { string memory str = "A76A95918C39eE40d4a43CFAF19C35050E32E271"; array1 = bytes(str); bytes memory str1 = hex"...
17
votes
6answers
9k views

How to convert a uint to bytes in Solidity?

Is there an easy way to convert a uint to bytes in Solidity?
4
votes
2answers
2k views

Concat two bytes arrays with Assembly

Does anyone know how to efficiently concat two bytes arrays with assembly language to save gas costs? Currently I have function mergeBytes(bytes param1, bytes param2) returns (bytes) { bytes ...
16
votes
2answers
12k views

What is the difference between bytes and bytes32?

I know bytes32 stores 32 bytes, but what does bytes store? And what is the difference between the two?
13
votes
2answers
2k views

Convert struct to bytes in Solidity

Is there any convenient way to convert (e.g. cast) a struct type to bytes? I'm trying to call a method like the one below (taken from here) where you can pass some (arbitrary) contextual info that ...
5
votes
2answers
5k views

passing String object with “0x..” value as bytes32 to a solidity function

I'm having trouble to pass bytes32 to a solidity function from javascript. It's converting to an incorrect bytes32 in solidity. The javascript is a test, running with truffle v3.3.1 on testRPC v3.0.5....
2
votes
0answers
359 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; ...
8
votes
1answer
5k views

How to pass arbitrary bytes to a function (2016)

I'm trying to implement a contract which will store bytes blob, a dynamic bytes array. For example I have following struct: Sign { address signer; bytes16 signType; bytes sign; } plus ...
6
votes
3answers
3k views

How to convert bytes to uint in Solidity

Hey is there a way to convert bytes to uint in Solidity?
3
votes
1answer
313 views

Why can't we do bitwise operations on Bools?

So I'm running an if/then comparator function with bools. It's essentially and xor function but when I tried a ^ b i get operator not compatible with types bool and bool. Given that bools (in ...
3
votes
1answer
3k views

How to return bytes array in Solidity Contract

I'd like to input & output an array of bytes (of approximately 56 characters each). The input works but the compiler gives a TypeError on bytes[] for the output function: TypeError: Internal type ...
2
votes
1answer
209 views

Reading bytes from bytes32 returns zero value (except first one)

Why always when I read some bytes from bytes32 only first read return a value, all following will return zeros? 0x00 bytes32 proof = 0x999e7640514e578f5b9b416469d270d559ad4186ef63da6cd63751373512735e;...
2
votes
1answer
746 views

Problem using created array from assembly

I've used the code from the solidity assembly tutorial here to create a single dimensional array in assembly. The code is as follows: contract C { function f(uint a, uint b) constant returns (uint[]) ...
0
votes
1answer
230 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 ...