Questions tagged [bytes32]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
13 views

Can you convert my address (bytes20) type to a bytes32 string?

I am running into an error for: TypeError: Type address payable is not implicitly convertible to expected type bytes32. Due to the fact that I am using my address ...
0
votes
1answer
55 views

Is it cheaper to store a string or convert it to bytes32 with abi.encodePacked()?

For example, in the code below, would it be cheaper to store the string in a mapping? Or to convert it to bytes32 and store it as bytes32 then convert it back to a string whenever I call it with ...
0
votes
0answers
17 views

Solidity: How to represent bytes32 as string

This may be simple in other languages but I can't figure out how to do it in Solidity. I have a bytes32 like this 0x05416460deb76d57af601be17e777b93592d8d4d4a4096c57876a91c84f4a712. I don't want to ...
1
vote
1answer
62 views

What does add(source, 32) do in solidity?

I understand what add() does. It used used in the assembly to perform additions. My question is why are we adding 32 here? What is the purpose of doing so? The full code is here
1
vote
1answer
312 views

bytes32 doesn't accept input

I don't understand what should input into bid() function. Whatever I do, it shows the same error: "Error encoding arguments: Error: invalid arrayify value (argument="value", value="...
0
votes
0answers
19 views

How much is the biggest BytesX type in solidity? (Bytes32?)

I'm trying to keep it simple while returning and array of strings. I want to return a fixed bytesX array with small text. How much is the possible X in the BytesX type? In Remix it seems to be Bytes32....
0
votes
1answer
34 views

Bytes32 and Data Payload question

Hello Solidity Expert, I am working on Ethernaut challenge 8 called Vault: Ethernaut See the contract code at the end of this post. I feel I solved the challenge but for some reason I cannot open the ...
2
votes
1answer
89 views

Most gas efficient way to check if byte array contains zeroes?

I have a contract that I pass data packed into an array of uint256 (as it's apparently cheaper to use uint256 over bytes32) and each byte in the uint256 contains positions referencing another array of ...
0
votes
1answer
26 views

When using mapping, why use an address over bytes32?

From an end user standpoint, they will never want to use the address for searching for mapped data when they could just submit a username for function parameters, so is there any specific reason why ...
1
vote
1answer
80 views

In Solidity, Is there any situation, when string is necessary?

In Solidity, Is there any situation, when string is necessary? Please can u explain when I should use string instead of bytes or bytesN? Thanks!
0
votes
1answer
524 views

How to pass bytes32[] array to call this function using web3 js?

I have a function function multiERC20TransferTightlyPacked ( ERC20 _token, bytes32[] _addressesAndAmounts ) public { for (uint i = 0; i < _addressesAndAmounts....
0
votes
1answer
40 views

Combine BytesX and BytesY to create BytesZ?

I am working on a Solidity Smart Contract (^0.5.10) where I want to return an array of Ratings elements. struct Ratings { address restaurant uint8 score }; Since returning Rating[], string[]...
1
vote
2answers
203 views

How to convert string to bytes256 or arbitrary bytes?

I already know how to convert bytes32ToString and stringToBytes32: function bytes32ToString(bytes32 x) public pure returns (string memory) { bytes memory ...
2
votes
1answer
37 views

Event and method different address type

This is my contract pragma solidity ^'0.5.2'; contract MyContract { address[] public contracts; event ContractCreated(address newAddress); constructor() public { } function ...
0
votes
1answer
116 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")...
2
votes
1answer
2k 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]; } ...
1
vote
2answers
2k 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
1answer
2k 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
876 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
2k 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
134 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 =...
4
votes
3answers
714 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
452 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
44 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
2k 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
295 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
196 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=...
4
votes
3answers
8k 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
507 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
86 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
537 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 ...
7
votes
3answers
3k 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
300 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
666 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
28 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 ...
1
vote
2answers
2k 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
429 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
413 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
198 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
279 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....
2
votes
0answers
335 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
3k 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
137 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
87 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
474 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
1k 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
429 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
115 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
205 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
204 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.