Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [bytes32]

The tag has no usage guidance.

0
votes
1answer
24 views

How to convert plain text string variable to bytes32 variable? And how to store bytes32 in one variable after converting? [duplicate]

pragma solidity ^0.4.25; contract Purchase { address public sellerAddress; constructor (address _sellerAddress) { sellerAddress = _sellerAddress; } } contract Buyer is Purchase {...
0
votes
2answers
63 views

bytes32/uint256 conversion

I am looking to take in a uint256 (in hex notation) and convert it to bytes32. For some reason I am not getting the same value after converting. function test(uint256 genes1) public returns (bytes32) ...
1
vote
1answer
38 views

Information lost when getting string from byte32 Solidiy smart contract

I have a number as a string which I pass to smart contract function as a parameter. The function takes byte32 as a parameter. Here is the node.js code for executing the contract function: const app =...
1
vote
3answers
58 views

How do I check if a bytes32 variable in a mapping has been assigned value?

For example, for: mapping(address => bytes32) public addressName; which one of the following syntax is correct? address _address = 0x...; //an actual address require(addressName[_address]!=""); ...
0
votes
2answers
47 views

Keccak256 check Key

So I need a function that checks if a key fits the hash of that said key. This is what I have: function checkKey(bytes32 hash, bytes32 privateKey) public returns (bool success) { require(...
1
vote
0answers
17 views

solidity variables to store decentralized identities keys — bytes32 sufficient for a ED25519 keys?

I am building a next generation decentralized identity solution. Would like to under which solidity variable is best suited to store decentralized identities keys -- bytes32 sufficient for a ED25519 ...
1
vote
2answers
433 views

How to convert bytes32 to string? [duplicate]

I input an string data as bytes32 type. Now i cannot return that string in readable form? any way to do that?
2
votes
0answers
148 views

Comparing solidity sha3 with web3 sha3 inside smart-contract

The problem is that sha3 in solidity returns bytes32 and I have a string returned from IPFS by oraclize, and if hash calculated in solidity and returned to web3js (bytes32 got interpreted as a string) ...
0
votes
1answer
84 views

copying bytes32 values from map to array

I am trying to copy stored values from a map to an array. I have the following code: pragma solidity ^0.4.21; contract test { event LogTest( bytes32[5] a ); bytes32[5] arr; mapping (uint=...
0
votes
1answer
1k views

Where can I find a string to bytes32 converter online?

So far I am using this solidity code pragma solidity 0.4.24; contract Converter{ function Converter(){ } function stringToBytes32(string memory source) returns (bytes32 result) { ...
-2
votes
1answer
181 views

Why does keccak256() return bytes32 instead of uint256 in Solidity?

A hashing function outputs an integer that is 256 bits long... so why not store it as such?
0
votes
1answer
48 views

Convert two int128 variables to Bytes32 and back

For Bytes32 to 2x int128 I have working code. I've adapted code from this stack Exchange answer function bytes32to2xint128(bytes32 z) pure public returns (int128 x, int128 y){ bytes16[2] memory ...
1
vote
1answer
159 views

web3.toAscii for foreign languages

I have a function that takes bytes32 _name as a parameter and store it in a struct. Let's say _name is either Chinese, Korean, or Japanese and from app.js I would convert the _name to hex to pass it ...
2
votes
2answers
549 views

Convert bytes32 to address

Is there a simple way to convert a bytes32, e.g. 0xca35b7d915458ef540ade6068dfe2f44e8fa733c, to an address? bytes32 data = "0xca35b7d915458ef540ade6068dfe2f44e8fa733c"; I tried casting it with ...
2
votes
1answer
89 views

bytes32 same length hex strings cost different gas why?

I can not understand the difference in gas for the following problem. I generated a sha256 hash value and the output i chose to be lowercase hexadecimal. So the output value is hexadecimal string of ...
0
votes
2answers
171 views

Solidity inserting data that maps addresses to arrays of bytes32 error

My contract is as follows: pragma solidity ^0.4.21; contract try { mapping (address=>bytes32[10]) Map; function try(){} function fill_map(bytes32[10] _attributes) public { ...
1
vote
0answers
22 views

Gas estimation failed when trying to input a list of bytes32[5]

I am trying to create a struct as shown in the code below. The function setData is intended to create an object of the struct, take the inputs (a string and a list of type bytes32[5]) and set their ...
0
votes
2answers
512 views

How to convert/decode Solidity bytes32 to Python string via web3.py

Inside a Solidity contract, I have this variable: zBytes32 = "HelloBytes32"; after Python web3.py retrieving that variable, zbytes32 = contractInstance.functions.getzBytes32().call() print(...
0
votes
1answer
252 views

Problem with invoking a function with byte32 parameter : “Given parameter is not bytes”?

We have a function as follows: function newObject(bytes32 _id, uint256 number_of_sub_states, bytes32[10] sub_states_types, bytes32[10] sub_states_values, address _owner) public returns(bool success) {...
0
votes
1answer
194 views

Setting values of an byte array dynamically

If I set the values of an array as follows, am I wrong? uint256 n = 0; bytes32[n] example; function getArraySize(uint256 arraySize) public returns(uint256 size) { size = arraySize; return size; }...
1
vote
0answers
135 views

cannot get return variable(s) in javascript when using require in solidity

I have a function in solidity that returns a few bytes32 variables. I cannot for the life of me access those variables. Can someone please help? function getData() public returns (bytes32, bytes32, ...
0
votes
1answer
130 views

Read String as bytes (Oraclize callback)

I have an Oraclize call that returns the following (a string): "00000000000000000000000000000000000000000000000000000000000003e8" Now this is 1000 (bytes32 hex) You can check here: https://www....
1
vote
0answers
22 views

Is there a ERC or existing EIP standard or a lib for String to Bytes32 and Bytes16 conversion?

Is there a ERC or existing EIP standard or a lib for String to Bytes32 and Bytes16 conversion ?
1
vote
0answers
145 views

How to pass bytes32 value from javascript?

I am using truffle and Ganache. I wrote the following code in remix and its working. But when I use the same code with javascript I am getting runtime error pragma solidity ^0.4.17; contract ...
2
votes
1answer
887 views

Problem with bytes32 values

I am facing problem with bytes32. Here is my sample contract: pragma solidity ^0.4.16; contract Test { bytes32 public input; function test(bytes32 _in) public { input = _in; } } ...
0
votes
0answers
507 views

Calling contract function with bytes array(bytes32[]) works in browser solidity but not with web3js

Trying to call function which takes bytes32 array as parameter. When tried with browser solidity, it worked fine. But same does not work with Web3JS. Both browser solidity(Remix) and Web3JS connected ...
1
vote
1answer
82 views

bytes32 comparison returning true when values are very near

Has this nagging question where bytes32 that are near to each other returns true on comparison. truffle(development)> 0x5b3138302c3132302c3135392c3232332c36342c3135392c36392c323821311a == ...
1
vote
1answer
73 views

Fixed-size array issue

Maybe this question it seems to be stupid but is it possible to change elements of fixed-size array like bytes32. For example: bytes32 _b32 = sha3(1); _b32[0] = 100; // => Error
1
vote
1answer
271 views

Calling mapping (uint ==> bytes32)return 0x0000000

contract test{ mapping(uint8 => bytes32) public check; uint8 [] public array; function Adddata(string document, uint8 number) returns (bytes32) { check[number] = sha256(document); ...
0
votes
1answer
710 views

string memory[3] memory is not implicitly convertible to expected type bytes32[] storage ref

I have the following (array of bytes32 types): bytes32[] public allTokenSymbols = ["0x4554480000000000000000000000000000000000000000000000000000000000", "...
1
vote
1answer
226 views

Invalid Op Code - passing bytes32 array to a contract method called from another method of another contract

I've been banging my head on this one for some hours, I'd appreciate any help :) This is a final edit to clearly state the issue: Is there a proper way to pass a bytes32 array to a method on contract ...
1
vote
0answers
88 views

Solidity extract a sub bytes32 from a source bytes32

I need to extract a sub-bytes32 from a source bytes32 so I wrote this solidity function: function bytesOf(bytes32 source, uint start, uint count) private pure returns(bytes32) { bytes32 result; ...
1
vote
1answer
91 views

Is it possible to change an already assigned bytes32 variable?

If I assign a bytes32 variable such as bytes32 x = 0xffff; but then I want to change the last byte (or any byte really) so that x is now 0xffaa, is there any possible way to do this? I want the ...
2
votes
1answer
123 views

Range of Bytes32

What is the unsigned range of a bytes32 type in Solidity? I'm wondering the total number of unique expressible combinations. I'm assuming it is 2^8^32.
4
votes
1answer
766 views

Why does require .length of bytes32 > 0 not work?

Why does the require not throw here when I am passing an empty string for the _name param? function MyContract(bytes32 _name) public { require(_name.length > 0); name = _name; }...
1
vote
1answer
595 views

Uint to Bytes32 conversion — how does this make sense [duplicate]

Pretty simple code here: pragma solidity ^0.4.13; contract Oracle{ event Print(string _name, bytes32 _value); bytes32 key; function Store(bytes32 _key) returns (bytes32) { key = ...
3
votes
2answers
336 views

Convertion from bytes 8,16,32 to String

I know it has been asked a lot of times but the newest post about this I could find was about 1 year old. To me it seems quite possible that things have changed since then. So my question: Is there an ...
0
votes
1answer
161 views

Smart Contract with web3j - Stored SHA hash returned is not the same as input

I have a contract that stores sha-256 hashes of documents (stored as bytes32). I also have a method to retrieve a hash that is mapped to a unique id for the document. However, when I retrieve and ...
2
votes
1answer
181 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
43 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
130 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
502 views

How to store a 300+ char string?

I'm trying to store the following string in a contract ...
4
votes
2answers
1k 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
528 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
4k 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
0answers
128 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;...
6
votes
3answers
1k 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 ...
4
votes
1answer
1k 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 ...
3
votes
2answers
311 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 ...