Questions tagged [bytes32]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
1answer
291 views

How can I split a 56 character input and store them in two Bytes32?

I want a function to accept, store and output 56 characters. My other question (How to return bytes array in Solidity Contract) shows that I tried to return bytes[], but it gives me an error: ...
1
vote
1answer
50 views

Dealing with mapping(string => string[])

I have a contract with different categories. We can assume them to be the following here: Cities Countries Counties Suppose I want to add a new city to the category cities. I'm assuming this has to ...
2
votes
1answer
184 views

How do I combine integers, to save gas on transaction data and storage?

For example, I have two integers: one is uint128, another is uint64. I want to store those two integers by converting them to bytes24. And when I use them, parse the bytes24 to uint128 and uint64. ...
5
votes
1answer
962 views

How to store a 300+ char string?

I'm trying to store the following string in a contract ...
5
votes
2answers
2k views

Why can I store over 32 characters in bytes32?

I have a Solidity contract with functions like this: function SetMessage (bytes32 key, bytes32 message) returns (bool success) { publicStruct[key].message = message; return true; } ...
3
votes
1answer
863 views

How to get byte32 similar data and return same index as ethereum wallet in web3.js?

Solidity byte32 return different value in web3, remix browser compiler and ethereum wallet In the contract, I have just added byte32 values and return it but in the web3 api, remix browser compiler ...
3
votes
1answer
2k views

How to return string over 32 characters from bytes32[] array?

I have a bytes32[] array. I convert strings to bytes32 before they are added to the array as follows: function stringToBytes32(string memory source) returns (bytes32 result) { assembly { ...
4
votes
1answer
6k views

How to convert a string to bytes32 array?

I have known how to convert a string to bytes32. But if the string length is longer than 32, the rest of the string will be truncated. So how to convert a string to bytes32[] array?
2
votes
1answer
310 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;...
9
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
2k views

Convert bytes32 to ordered bytes2, bytes4, etc

For example, I need to slice my bytes32 variable to chunks, and put result into 5 variables, saving the order, bytes2, bytes2, bytes2, bytes2, bytes8, bytes1 (aka byte), the order should be saved and ...
2
votes
2answers
533 views

blockHash compression problem inside a contract, block.blockhash(blockNumber) returns “0x” or random hash value

Related to following answer: function block_hash_validation(uint blockNumber, bytes32 blockHash) constant returns(bool isValid) { return (block.blockhash(blockNumber) == blockHash); } When ...
19
votes
2answers
15k 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?
42
votes
2answers
34k views

Use string type or bytes32?

What are the benefits to using string datatypes over bytes32 to represent text data. It seems my contract runs into an out of gas exception when I switch the data structures from bytes32 to string.
5
votes
2answers
711 views

bytes - quotes or not?

I have a contract with a function that takes as parameter a bytes32, and a mapping that uses a bytes32 as key. In geth, it seems like I can call contract.foo("0x123abc") and contract.foo(0x123abc), ...
3
votes
3answers
4k views

Keccak256(parameter) How to pass a string to be hashed?

I'm trying to do something that in theory is very simple: I want to pass a string like "hello" to a function and then compute the sha3/keccak256 hash. I think the problem is that if the parameter is a ...
36
votes
4answers
33k views

How to convert a string to bytes32?

How can I convert a string to a bytes32? Does anyone has a magic function or library which does it? For example: This works since as input I gave 32-bits. But it won't work with "> 32-bit" chars. ...
9
votes
1answer
11k views

How to get string from hex on Smart Contracts results [duplicate]

On a Smart Contract called "mem" there is a function called "get()" that returns a bytes32 that is supposed to be a string. How can I decode the string? The result is an hex value. I have tried ...
8
votes
1answer
7k views

How many letters can bytes32 keep?

I would like to add strings into bytes32. What is the maximum number of letters bytes32 can have?
3
votes
1answer
175 views

ethjsonrpc /python /bytes32 type argument assertion

When I use the ethjsonrpc, some problem about bytes32 type argument assertion occurs as the picture shows. I don't know where the problem lies and the correct way to assert the bytes32 type argument ...
7
votes
1answer
632 views

Calculating difficulty and verifying a hash as a solution

I have a scheme right now where individuals are committing to a contract a solution to a problem similar to Bitcoin's proof-of-work protocol. Here's the basic flow...the contract calculates a seed ...
30
votes
2answers
9k views

Why do Solidity examples use bytes32 type instead of string?

In many Solidity examples I read that use strings for parameters or return values, I see they are typed as bytes32 although there's a string type. What is the real reason for that? Thanks.
5
votes
2answers
4k views

bytes32 to uint conversion is incorrect

I instantiate the following contract with _number as 10. When I check the value of number, I get 72370055773322622139731865630429942408293740416025352524660990004945706024960. Is this a problem with ...
6
votes
3answers
3k views

How can I modify bytes32 result to uint?

I want to separate three last digits of the most recent block header hash and get the result as uint. I can get the answer as bytes32 by this code, but how can I change this result to uint? contract ...
13
votes
2answers
6k views

Convert with JS a Solidity bytes32 to a Solidity string

I have functions which are forced to return a bytes32 object, but then in my webapp I need to reconvert them to a classic string. How can I do that?
37
votes
6answers
32k views

How to convert a bytes32 to string

How can I convert a bytes32 to a string? Does anyone has a magic function or library which does it?

1
2