Questions tagged [data-types]

The tag has no usage guidance.

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

Ethers-EIP712 wont work with strings

I tried to use eip-712 signature with my smart contract but I found out that it only work with fixed-size type. Does anyone know how I can use dynamically-Sized types like string, arrays and bytes ...
user avatar
1 vote
0 answers
31 views

Copying strings and bytes from memory to storage via storage references

What's the proper way to copy a string (or bytes) from memory to storage? When copied directly into a state variable lvalue (or into a mapping), there's no problem, but when assigning a string memory ...
user avatar
0 votes
1 answer
15 views

Passing different data types to uint parameter

I found out, that I can pass different data types (as argument), even if the Solidity method takes only uint data type, why is that possible? Example: function test (uint _param) public { //do smth ...
user avatar
  • 77
1 vote
0 answers
12 views

Why cannot insert elements dynamically into 2D memory array

I have some issues with understanding exactly how the arrays and memory works in solidity, but I found this nice question that kind of help me to understand some parts - Solidity 2D in-memory array ...
user avatar
  • 21
2 votes
2 answers
46 views

What type is "MyInterface.MyCustomError" in Solidity?

I'm toying with the recently introduced custom errors. Here's a mini replica of my set up: interface MyInterface { error MyCustomError(); } I'm writing my tests in Solidity and I'd like to use ...
user avatar
0 votes
0 answers
89 views

Integrate Metamask in Angular

I am trying to integrate metamask in the Angular app, but Typescript does not know the type of window.ethereum What libraries should be added to get the type of ethereum object. I tried @metamask/...
user avatar
0 votes
0 answers
16 views

UniswapV3 Pool Liquidity

function liquidity() external view returns (uint128) Which side of the asset pair is referenced here, or is that value in ETH? How do I scale it properly?
user avatar
1 vote
2 answers
21 views

What is the Order of Execution of data types?

I have created and deployed(Remix) a simple contract to understand better data types. When I deploy contract, I see that data types are not in the order inside the contract. Here is my contract: ...
user avatar
1 vote
1 answer
16 views

Memory to memory assignment doesn't point to the same reference

Hey I am trying to understand data location more it is stated in the docs that "Assignments from memory to memory only create references. This means that changes to one memory variable are also ...
user avatar
0 votes
1 answer
52 views

Using a dynamic array for an index vs a fixed array

I'm going to be using a smart contract to add data to an array, so I'll be using array.push (fixed gas). The data added is an address and the purpose of the array is just to keep a list of all ...
user avatar
0 votes
1 answer
13 views

how and where to use data areas

from https://docs.soliditylang.org/en/v0.8.11/types.html: " If you use a reference type, you always have to explicitly provide the data area where the type is stored" But later they give ...
user avatar
0 votes
1 answer
208 views

How to convert between uint256[] and uint256[x]

Basically, I want to call a function myfunct(uint256[] memory) but I have a uint256[13] I have the uint256[13] because I want to temporarily store uint256s in a function, and save memory--not do ...
user avatar
0 votes
1 answer
198 views

How to convert uint8 to uint256 bitmap in solidity?

Say I have a uint8 with binary value 0000_1001 i.e. 8+1=9 in decimal. How do I convert this uint8 in a gas efficient way to a uint256 which represents a bitmap?, such that in this example the 9th bit(...
user avatar
  • 230
0 votes
2 answers
397 views

Problem compiling subgraph with graph-ts new version

I'm getting this error: ERROR TS2322: Type '~lib/@graphprotocol/graph-ts/common/value/Value | null' is not assignable to type '~lib/@graphprotocol/graph-ts/common/value/Value'. I know it is for this ...
user avatar
1 vote
1 answer
274 views

Why do you have to specify calldata or memory for complex types?

Why do you have to specify calldata or memory for complex types like (string, array, struct etc)?
user avatar
1 vote
1 answer
300 views

Solidity 2D in-memory array with size defined by a variable

I want to define an in-memory 2-dimensional array without fully hard-coding its shape. Let's say I want a 3xN matrix (and to explain ill also set its 0th element to [1, 2, 3]): function makeArr (int n)...
user avatar
0 votes
1 answer
204 views

Subgraph (Graph Protocol) not building out of schema correctly

Doing a quick start tutorial to get back in the subgraph mode and my mapping (even though very simple) is not building. The types will compile, but I cannot deploy it due to it being unable to build. ...
user avatar
  • 45
0 votes
1 answer
47 views

Storing struct with mapping inside of mapping

I have the following structures defined in my smart contract: mapping(bytes4 => Question) private questions; struct Question { bytes8[] answers; mapping(bytes32 => bool) answerers; } ...
user avatar
  • 101
0 votes
1 answer
123 views

what does "int x = type(int).min;" mean in Solidity? [duplicate]

In the Solidity docs, "if you have int x = type(int).min;, then -x does not fit the positive range.This means that unchecked { assert(-x == x); } works, and the expression -x when used in checked ...
user avatar
1 vote
1 answer
181 views

Where are value-type function arguments stored in Solidity?

When we define a function, say test(uint256 val). I would presume val would be implicitly defined in memory. But what if we change the funtion visibility modifier, does that change the location of ...
user avatar
1 vote
2 answers
512 views

Address to String solidity

I am using this code in converting address to string in solidity function toAsciiString(address x) public returns (string memory) { bytes memory s = new bytes(40); for (uint i = 0; i < 20; ...
user avatar
  • 23
1 vote
1 answer
198 views

Best way to store percentages in a smart contract

I need to store the IRR (internal rate of return) of a project in my smart contract. Since Solidity can't store decimals it must be saved as an integer. Which of these options would be better and why: ...
user avatar
0 votes
2 answers
389 views

How to implement a Set in solidity?

How to implement a Set in solidity that fulfills the following criteria? Add and remove items Check if an item is present Iterate the Set
user avatar
1 vote
1 answer
103 views

What is the difference between contract type and address?

I have seen here that: Contract TokenCreator { function createToken(bytes32 name) public returns (OwnedToken tokenAddress) { // Create a new `Token` contract and return ...
user avatar
  • 1,353
0 votes
1 answer
53 views

Data Stream Processing on Ethereum

I developed a system that receives continual streams of requests via a REST API. For each bit of data contained in the body of the request, the sender receives an according bit of data in the response....
user avatar
0 votes
1 answer
195 views

Mapping in solidity

Mapping do not have a length, nor do they have the concept of key or a values being set. Is this statement True or False? Please provide the explanation also. The solidity docs say “Mappings can be ...
user avatar
1 vote
0 answers
82 views

Alias for external library type?

Say you're importing a library, and that library contains a struct: pragma solidity >=0.8.0; library SomeLibrary { struct FooType { uint256 value; } } contract SomeContract { ....
user avatar
4 votes
1 answer
398 views

How do you handle the hex prefix without the value (only "0x")?

First, I'm caling function foo() (from another contract) that returns me a uint in the form of bytes. Then, I'm using BytesLib.toUint(foo(), 0) to retrieve the uint. When the value is supposed to be 1,...
user avatar
1 vote
1 answer
596 views

error comparing two bytes memory

I am testing a smart contract in Remix and I get the following error when trying to compare two bytes memory using "==": TypeError: Operator == not compatible with types bytes memory and ...
user avatar
2 votes
1 answer
314 views

"generic object" data type in solidity

Is there a data type similar to "object" in C# that any solidity data type could rely on? I currently have a struct with multiple fields and I would need one of them to be either a string, a ...
user avatar
0 votes
0 answers
17 views

Mapping with different datatypes showing on one struct

is it possible that in I can use a uint and a address that showing on the same struct(Submission) as mapping ? I need something what makes it easy to read out the mapping with a uint (number) and with ...
user avatar
  • 11
1 vote
1 answer
109 views

What happens when the result of the shift operation does not fit in the type of the left operand?

For instance, take the following code: pragma solidity ^0.8.0; function foo() external pure returns (uint256, uint256, uint256) { uint256 i1 = uint256(2) << 255; uint256 i2 = uint256(4) ...
user avatar
1 vote
2 answers
178 views

uint16 conversion issue

So I want to test this Solidity code using Typescript but faced with a type conversion issue. uint16 base; function addNumberToBase(uint16 number_) { // This number must be between 1 ~ 5 ...
user avatar
  • 73
0 votes
1 answer
495 views

best data type for SHA256 hash

I'm trying to find a better data type for storing SHA256 hash, right now I'm using string, and I'm thinking of switching to byte32 but considering it I don't know if this is really a step in the right ...
user avatar
0 votes
1 answer
218 views

Difference between byte and uint8 datatypes in solidity

I want to understand if there is a difference between byte data-type and uint8 in solidity ? Thanks
user avatar
  • 1,089
6 votes
2 answers
556 views

Is it worth to store Ether at the full precision in database?

Ether has precision of 10^18 which makes it impossible to use BIGINT type in database to store values in weis: DECIMAL type should be used instead. Is it worth to store values in Gwei to stay with ...
user avatar
0 votes
1 answer
634 views

Difference between a byte in a bytes32 and a byte in a bytes structure

One can read in the docs: A bytes is similar to byte[], but it is packed tightly in calldata and memory. What does this exactly mean? For instance, according to this link, why should we convert a ...
user avatar
2 votes
1 answer
90 views

Library for Ethereum types?

Is there a library for Ethereum types, for tests written in TypeScript? For example, an address type would be better to use instead of a generic string for Ethereum accounts.
user avatar
0 votes
1 answer
399 views

Data location must be "calldata" for parameter in external function,

I'm getting the following error: Data location must be "calldata" for parameter in external function, but "memory" was given. for the following function: function _registerAirline(address ...
user avatar
  • 587
2 votes
1 answer
39 views

Why is the first item of an int array type casted to an int?

I was reading a book on solidity, the array was defined as int[5] age= [int(10),20,30,40,50] When data type int was declared at the start then why it is declared again in the array with 10?
user avatar
3 votes
1 answer
117 views

Can I add an int32 to an int256?

I'm trying to reduce the storage size of my contracts by reducing the bytes required to store my int data types (among other things). Can I get the best practice for adding int256 and other smaller ...
user avatar
0 votes
1 answer
39 views

Does it make sense to require token value to be anything but negative to prevent hack (more details below...)?

I was asked to validate a smart contract for a token and a function that puzzled me looks like that: function transferFrom(address _from, address _to, uint tokens) { require(...
user avatar
3 votes
1 answer
730 views

Why use anything but uint256/int256 outside of a struct?

I see how uint8 can save space within a struct, but outside of that I do not see any reason to use anything but uint256. The gas cost is slightly higher for uint8. The only reason I can think of is ...
user avatar
2 votes
1 answer
224 views

How are we able to send 512 bit hash as a bytes32 variable?

I have a code that is working: solidity function checkSignature(bytes32 h, uint8 v, bytes32 r, bytes32 s) public pure returns (address signer) { bytes memory prefix = "\x19Ethereum Signed ...
user avatar
  • 1,129
1 vote
1 answer
317 views

is there a list type in solidity?

I know there are dynamically sized arrays, but I need a data structure that can remove elements from the middle cheaply. Using pop() with a dynamically sized array should require a shift of every ...
user avatar
1 vote
1 answer
3k views

Solidity, problem with bytes decoding

back with another question towards solidity Guru's. I am trying to call a method which takes bytes array as an input, but either I am encoding this parameter wrongly or decoding it wrongly. Solidity ...
user avatar
  • 359
6 votes
2 answers
6k views

Solidity Invalid implicit conversion from string memory to bytes memory requested

pragma solidity ^0.5 contract ProofOfExistence { // ... some code here function proofFor(string memory document) public view returns(bytes32) { return sha256(document); } //...
user avatar
3 votes
1 answer
174 views

Understanding first evm word of reference types in assembly

Given the following function: function getArrayItems(bytes calldata) external returns ( bytes4 _signature, bytes32 _wutIsThis, bytes32 _length, bytes32 _firstItem ) { assembly { ...
user avatar
2 votes
2 answers
105 views

Validate bytes16 argument size

I have a function which accepts one bytes16 argument. function start( bytes16 reference ) I have some events which I use to track behaviour, using reference as the index. Everything works ...
user avatar
1 vote
0 answers
336 views

How to decode Tx data? Online tool?

Is there a fast way to decode the data returning from a Smart Contract call? I know there are github projects with JS libraries to decode this kind of data (such as https://github.com/ConsenSys/abi-...
user avatar