Questions tagged [bytes32]
https://docs.soliditylang.org/en/v0.8.13/internals/layout_in_storage.html?highlight=string#bytes-and-string
85
questions
0
votes
1
answer
47
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
135
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
70
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
807
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
339
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
136
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
273
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 ...
0
votes
1
answer
246
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 ...
2
votes
1
answer
399
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
2
answers
1k
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
112
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
1
answer
208
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
73
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
112
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!
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....
0
votes
1
answer
72
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
2
answers
406
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
55
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
1
answer
236
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
4k
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];
}
...
3
votes
2
answers
4k
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
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
1k
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
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) ...
1
vote
1
answer
252
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 =...
5
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]!="");
...
0
votes
2
answers
737
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
0
answers
56
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
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
369
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
247
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) {
...
-2
votes
1
answer
797
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
1
answer
105
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
709
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
5k
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
1
answer
446
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
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
4k
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
1
answer
518
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
1
answer
444
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
0
answers
238
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
1
answer
287
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
0
answers
450
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
1
answer
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
1
answer
152
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
1
answer
104
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
1
answer
541
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);
...