Questions tagged [bytes32]

https://docs.soliditylang.org/en/v0.8.13/internals/layout_in_storage.html?highlight=string#bytes-and-string

Filter by
Sorted by
Tagged with
0 votes
0 answers
18 views

Convert kecka256 hash string back to bytes32

I am storing kecccak256 to hash some string value and store it as mapping. mapping(bytes32 => address) internal _owners; and my mint function looks like this - function _mint(address to, string ...
1 vote
1 answer
29 views

How to compare string and bytes32 in an optimal way?

I have keccak256 string encrypt in blockchain and keccak256(decrypt) bytes in function. This code works well. I pass an unencrypted string to the function and check it for validity. // SPDX-License-...
0 votes
1 answer
84 views

How to define a constant `bytes32` in Solidity v0.8 and above?

I want to define a constant bytes32 like this: bytes32 internal constant FOO = bytes32(0x01); But I'm getting the following error when compiling the code above: Explicit type conversion not allowed ...
0 votes
1 answer
73 views

How to decode a bytes that represent a function call without having the function parameters types?

I have a Smart Contract that receives transactions proposal, these proposals go through a voting period and when this period ends, the transaction can be executed if it has the necessary approving ...
0 votes
0 answers
15 views

bytes32 inout dosen`t work in my code

this my code : // SPDX-License-Identifier: MIT pragma solidity 0.5.2; contract Record5keccak { struct Attribute { bytes32 comment; uint expiredTime; } mapping(bytes32=&...
0 votes
1 answer
183 views

How can i change the 5th and 6th byte from bytes8

Hi Guys , How can i change the 5th and 6th byte from this bytes8 0x3FcB875f"0000"ddC4,or just arrive at this solution where: last four bytes(of bytes8) are this way 0x********"0000ddC4&...
0 votes
0 answers
209 views

How to pass a bytes32 hash to a contract

I am working with the contract deployed to Mumbai here. You'll see a few transaction errors from me trying to run the below code (using Alchemy). I am trying to hash the input startupName locally so ...
1 vote
1 answer
107 views

Querying an ethereum contract without ABI, with only input bytes

I know some transaction has some input bytes to the contract as specified by Etherscan or a mining pool (for instance, this transaction has input data that looks like 0x000000062de258...9b1d). I know ...
0 votes
1 answer
2k views

Convert number to bytes in ethersjs?

I have a number in javascript: const oracleResponse = 1 And I have a function that takes a bytes32 as input parameters function fulfillOracleRequest( bytes32 _requestId, bytes32 _data ) I ...
0 votes
1 answer
432 views

Try to mint from a contract but the hash is missing

function mint(bytes32 hash) external { require(!_hasMinted[msg.sender]); require(totalSupply() + premineRemaining < 500); require(hash == sha256(abi.encodePacked(msg.sender, ...
0 votes
2 answers
179 views

sha256 works with string memory but doesn't work with bytes32

The problem occurs when generating a sha256 inside contract. This works fine: function SimpleHash(string memory val) public returns (bytes32) { bytes32 h = sha256(abi.encodePacked(val)); ...
0 votes
1 answer
412 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
1 answer
2k 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 ...
  • 392
1 vote
1 answer
492 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 ...
  • 11
2 votes
1 answer
671 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,483
1 vote
2 answers
2k 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
1 answer
160 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 ...
  • 129
2 votes
1 answer
286 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
1 answer
107 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
1 answer
117 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!
  • 21
1 vote
1 answer
2k 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....
  • 196
0 votes
1 answer
91 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[]...
  • 83
1 vote
2 answers
504 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
1 answer
56 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 ...
  • 131
0 votes
1 answer
307 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
1 answer
5k 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]; } ...
  • 323
4 votes
2 answers
5k 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 ...
  • 681
2 votes
1 answer
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
1 answer
2k 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 {...
  • 367
0 votes
2 answers
3k 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) ...
  • 583
1 vote
1 answer
278 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 =...
6 votes
3 answers
2k 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]!=""); ...
  • 61
0 votes
2 answers
828 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
1 vote
0 answers
57 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,885
1 vote
2 answers
3k 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
0 answers
384 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
1 answer
261 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
5 answers
9k 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) { ...
  • 641
-2 votes
1 answer
870 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?
  • 211
0 votes
1 answer
118 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
1 answer
760 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 ...
8 votes
4 answers
6k 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 ...
  • 1,162
2 votes
1 answer
502 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 ...
  • 149
0 votes
2 answers
1k 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
0 answers
31 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 ...
2 votes
3 answers
5k 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(...
  • 1,500
0 votes
1 answer
535 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) {...
  • 2,518
0 votes
1 answer
471 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; }...
  • 2,518
1 vote
0 answers
249 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, ...
  • 111
0 votes
1 answer
293 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....
  • 3,590