Stack Exchange Network

Stack Exchange network consists of 175 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 format contract params expecting bytes32?

I have a contract that expects a bytes32 parameter called "topic" which I pass in like this: web3.utils.hexToBytes(web3.utils.stringToHex("Weather")); I also tried web3.utils.stringToHex("Weather")...
0
votes
0answers
13 views

Function doesn't return any value but modify the data in the contract

I have a function that can retrive all data and one for retrive only not readed data. On Remix with JavaScrpit VM it's work, but on Remix with my private blockchain linked with web3 provider the ...
0
votes
1answer
236 views

How to convert string to bytes32 properly?

In my solidity I'm using a mapping like this: mapping(bytes32 => uint) items; constructor() { items["test"] = 2; } function getItem(bytes32 key) returns(uint) { return items[key]; } ...
0
votes
1answer
229 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 ...
1
vote
1answer
281 views

Invalid bytes32 value [duplicate]

I am trying to learn about solidity so I just watch a tutorial about it, I already copy the same code as the tutorial but there is an error with bytes32. Here it is: That is the deploy code: And ...
0
votes
1answer
96 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
240 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
47 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 =...
2
votes
3answers
153 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
106 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
27 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
745 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
214 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
121 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
3answers
2k 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
236 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
51 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
230 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 ...
3
votes
3answers
954 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
123 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
244 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
24 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
709 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
303 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
270 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
158 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
190 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
175 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 ...
3
votes
1answer
1k 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; } } ...
1
vote
1answer
100 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
77 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
340 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
893 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
2answers
273 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
95 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; ...
2
votes
1answer
122 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
148 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.
5
votes
1answer
973 views

How to check if a bytes32 represents an empty string?

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
658 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
384 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
182 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
239 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
45 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
151 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
612 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
591 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
5k 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
145 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;...