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
2 answers
20 views

When should I choose lower-size bytes variables (e.g. bytes23) over bytes32 variables?

I am trying to manage strings on a smart contract. I know these strings will be 46 bytes long so I thought I could convert them into bytes and split them in two bytes32 arrays. Then I realized smaller ...
Pietro D'Amico's user avatar
1 vote
1 answer
61 views

Manipulate bytes with assembly

Using assembly only, how do I switch, for A0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, the last 20 bytes of the second 32-bytes from the bytes variable below, and keep the rest as it is? Original bytes: ...
dNyrM's user avatar
  • 904
1 vote
0 answers
17 views

What does this function actually do in ERC1820?

I am unable to understand these two functions from the ERC1820 contract and its use. What does it actually do under the hood? Function 1 : /// @notice Checks whether the hash is a ERC165 interface (...
Serenity's user avatar
  • 125
0 votes
1 answer
482 views

Ethers.js solidityPackedKeccak256 to bytes32

I have a commit-reveal pattern implemented in my Solidity smart contract. I use the keccak256 encryption function to secure the player's commitment. How can I convert the return value of ...
Mila A's user avatar
  • 1,179
1 vote
0 answers
27 views

how to prevent array from occupying slots in solidity

I have this simple contract // SPDX-License-Identifier: MIT pragma solidity ^0.8.8; contract Ejemplo { //[123,456,789] input function test(uint256[] calldata nums ) external { } } ...
jhonatanalfred's user avatar
0 votes
1 answer
42 views

mapping not showing any value corresponding to string key(converted from bytes32)

I have bytes32 data which needs to be converted into a string, then use to get value from mapping(string => string) Trying to convert bytes32 to string using : string(abi.encodePacked(temp)) It is ...
Harman Singh's user avatar
0 votes
1 answer
33 views

Hash an array of variables and reverse hash them off chain

I'm trying to accomplish a task but I'm not sure how to approach the problem. I want to hash some variables inside a byte32 array. For example: ["Hashley", 32, "Random string"] -&...
Allennick's user avatar
  • 243
0 votes
1 answer
128 views

Passing bytes32 to constructor

I have s constructor that takes a bytes32 parameter and assign its value to the jobID variable contract APIConsumer { bytes32 public jobId; constructor( bytes32 _jobId) { jobId = ...
noro meb's user avatar
  • 338
0 votes
2 answers
134 views

bytes5 vs string

I have an smart contract with some defined fixed length variables from 3 to 5 characters long. Defining these variables as string is more intuitive for those that come from another languages. Also ...
pellyadolfo's user avatar
2 votes
1 answer
104 views

How to reverse a Solidity bytes sorting?

Suppose I have this bytes pad: 0x0123456789abcdef How can I make it like this: 0xfedcba9876543210 Just by Solidity and not by Assembly.
Alireza's user avatar
  • 533
0 votes
0 answers
63 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 ...
Ujjwal Kumar Gupta's user avatar
1 vote
1 answer
70 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-...
Alex Baker's user avatar
1 vote
1 answer
765 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 ...
Paul Razvan Berg's user avatar
0 votes
1 answer
586 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 ...
Kevin Kons's user avatar
0 votes
1 answer
622 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&...
Vadim Chilinciuc's user avatar
1 vote
1 answer
338 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 ...
John Targaryen's user avatar
1 vote
1 answer
7k 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 ...
Patrick Collins's user avatar
1 vote
1 answer
557 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, ...
Attila Kerekes's user avatar
0 votes
2 answers
350 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)); ...
Pedro Henrique Bufulin de Alme's user avatar
0 votes
4 answers
1k 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 ...
ConfusedDev's user avatar
0 votes
1 answer
4k 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 ...
Adrian D.'s user avatar
  • 544
1 vote
1 answer
914 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 ...
chnksi's user avatar
  • 11
3 votes
1 answer
1k 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
YulePale's user avatar
  • 1,843
2 votes
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="...
Rostyslav Dzhohola's user avatar
0 votes
1 answer
245 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 ...
Picard78's user avatar
  • 139
2 votes
1 answer
425 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 ...
AndroidNoob's user avatar
0 votes
1 answer
170 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 ...
user3316323's user avatar
1 vote
1 answer
131 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!
xxs's user avatar
  • 31
1 vote
1 answer
3k 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....
bbnn's user avatar
  • 236
0 votes
1 answer
170 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[]...
3mrsh's user avatar
  • 93
1 vote
2 answers
688 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 ...
Lou Treaser's user avatar
2 votes
1 answer
76 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 ...
overcomer's user avatar
  • 131
0 votes
1 answer
412 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")...
skrrrraaaa's user avatar
2 votes
1 answer
6k 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]; } ...
MarcS82's user avatar
  • 323
7 votes
2 answers
7k 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 ...
Radek_pl's user avatar
  • 791
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 ...
Jorge Navarro's user avatar
0 votes
1 answer
3k 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 {...
Rudrika's user avatar
  • 407
0 votes
2 answers
4k 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) ...
0TTT0's user avatar
  • 672
1 vote
1 answer
309 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 =...
Apar Adhikari's user avatar
7 votes
3 answers
3k 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]!=""); ...
Daniel's user avatar
  • 71
0 votes
2 answers
1k 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(...
polki's user avatar
  • 1
1 vote
0 answers
62 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 ...
Nathan Aw's user avatar
  • 1,954
1 vote
2 answers
4k 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?
MYANZIK shrestha's user avatar
2 votes
0 answers
444 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) ...
Andrew Katsewich's user avatar
0 votes
1 answer
304 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=...
Fawzy3881's user avatar
4 votes
7 answers
11k 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) { ...
Senju's user avatar
  • 701
-2 votes
1 answer
1k 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?
luca590's user avatar
  • 221
0 votes
1 answer
157 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 ...
user1938620's user avatar
1 vote
1 answer
876 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 ...
bbusdriver's user avatar
  • 1,144
8 votes
4 answers
10k 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 ...
Chris's user avatar
  • 1,302