Skip to main content

Questions tagged [data-types]

The tag has no usage guidance.

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

Default values of bytes1 to bytes32?

Beginner here who is trying to read https://docs.soliditylang.org/en/latest/control-structures.html#default-value about default values of data types. While all the other default data types described ...
Kojrey's user avatar
  • 1
0 votes
1 answer
24 views

What is `local storage` as opposed to `storage`

From solidity docs (https://docs.soliditylang.org/en/v0.8.4/types.html#data-location ) - Every reference type has an additional annotation, the “data location”, about where it is stored. There are ...
shadow's user avatar
  • 110
1 vote
1 answer
267 views

Why do two interfaces have the same ID even if one of them inherits from another interface?

Take a look at this code: pragma solidity >=0.8.26; import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; interface IFoo1 is IERC165 { function ...
Paul Razvan Berg's user avatar
0 votes
0 answers
12 views

invalid BigNumber string

Say I wanted to create a slightly modified ERC-721, which tracked its historical metadata states. Something like so: // SPDX-License-Identifier: MIT pragma solidity ^0.8.26; import { ERC721 } from &...
Abraham P's user avatar
  • 103
1 vote
1 answer
26 views

abi.decode() does not accept "address payable" as type

function myStatic() public returns (uint256[] memory, address payable[] memory, bytes32, string memory) { bytes memory encodedResult; bool success; (success, encodedResult) = address(...
user130657's user avatar
0 votes
0 answers
12 views

Invalid type for argument in function call. Invalid implicit conversion from uint32 to address requested. I tried typecasting it but still doesn't wk

cyborg@DESKTOP-S7TDG7E:~/solidity-course/foundry-f23/foundry-smart-contract-lottery-f23$ forge test --mt testFulfillRandomWordsPicksAWinnerResetAndSendsMoney -vvvv [⠑] Compiling... [⠔] Compiling 6 ...
Yusuf Musa's user avatar
0 votes
0 answers
21 views

Type casting error, but variables are the same types?

Despite the two sides are same type I took conversion error. here is my Deploy Contract: contract DeployFundMe is Script { function run() external returns(FundMe){ vm.startBroadcast(); ...
Düzgün Doğan's user avatar
0 votes
1 answer
19 views

confusion in reference type in solidity

Suppose a struct is made in solidity and pushed the same struct to an array and a mapping (assume a random key), will the change in struct accessed through mapping will affect the change in the same ...
Niladri's user avatar
  • 11
2 votes
1 answer
41 views

Has Solidity Introduced Storage Optimization for Smaller Integer Types in Structs?

I am working on a project where storage efficiency is of utmost importance. Specifically, I have a scenario where I want to store an ID of type uint16 and a code of type uint8. The current plan is to ...
MShakeG's user avatar
  • 1,735
1 vote
1 answer
81 views

How to create a hash based on struct array types?

I have the following arguments to call a function in a smart contract: ERC20Reward[] calldata _erc20Rewards ERC721Reward[] calldata _erc721Rewards ERC1155Reward[] calldata _erc1155Rewards ...
Falcon Stakepool's user avatar
0 votes
1 answer
71 views

TypeError: Type is not callable in my code

I started learning solidity, and I try to make a basic contract that add stocks to specific addresses. Here it is: pragma solidity 0.8.8; contract faya{ holders[] public investors; ...
FNH's user avatar
  • 105
0 votes
0 answers
27 views

How to fix Integer Overflow warning in oyente?

I was working with smart contracts and was testing my contracts using oyente. I am getting integer overflow warning in my contract and i dont know how to fix it. Can anyone help ? Thanks in advance. ...
Porkodi Ishwarya's user avatar
1 vote
1 answer
344 views

What's the best way to verify an address is correct in C#?

Is there an easy way to validate an Ethereum address in C#? Basically, I am looking for the method that correspond to these ones in Javascript but in C#.
Falcon Stakepool's user avatar
4 votes
2 answers
2k views

What is calldata offset for dynamic calldata arrays?

The Solidity docs say this about dynamic calldata arrays: For dynamic calldata arrays, you can access their calldata offset (in bytes) and length (number of elements) using x.offset and x.length But ...
Paul Razvan Berg's user avatar
1 vote
1 answer
243 views

How to silence warnings in return variables when they are not used?

I have the following function in solidity: function validateAndPayForPaymasterTransaction( bytes32, bytes32, Transaction calldata _transaction ) external payable override onlyBootloader ...
Falcon Stakepool's user avatar
0 votes
1 answer
206 views

Comparison of gas cost in different types of data storage

I want to compare gas fee of different types of data includes: String, bytes, uint, bool, int, address and etc... does anyone knows how much they costs? or share a link about this? Thank you
Alireza's user avatar
  • 360
1 vote
1 answer
438 views

Return type of `type` function in solidity

In solidity, you can call the type function to get information about a type. But what is the return type of the type function? // SPDX-License-Identifier: MIT pragma solidity 0.8.7; contract TypeTest ...
Patrick Collins's user avatar
4 votes
1 answer
35 views

Is it possible to use interface functions as types?

I would like to use a function defined in an interface as a function type, like this: pragma solidity >=0.8.17; interface Foo { function myFunction() external; } contract Contract { ...
Paul Razvan Berg's user avatar
0 votes
2 answers
155 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
3 votes
2 answers
579 views

Do the tight variable packing rules apply to arrays in structs?

Tight variable packing is a known coding pattern in Solidity for saving gas by placing variables that are lower than 256 bits closer to one another in structs. For instance, the following will cost ...
Paul Razvan Berg's user avatar
0 votes
1 answer
752 views

21 bytes Ethereum address with "0x" in 20 bytes address data type

I am learning solidity. Public address is dervied from last 20 bytes of public key. I have read that address data type has 20 bytes size and in many programme I have seen that they are equated to an ...
Brijesh's user avatar
  • 43
0 votes
2 answers
328 views

correct solidity type for a cid?

Im writing a function in solidity where the user enters a CID from an IPFS link, which looks like: QmcQvCyLAncpEzvmYtKfvVPVayGqFvTQrYpUpPAJeoXGke So far im using string type, and it works. Which is ...
Xunorus's user avatar
6 votes
2 answers
4k views

How to call function with struct parameter in ethers?

My solidity: contract Test { struct Num { uint value; } function double(Num calldata num) external pure returns(Num memory) { return Num({ value: num.value * 2 }); } }...
António Gonçalves's user avatar
0 votes
2 answers
33 views

Is Ethereum capable of having dynamicly typed languages?

I am wondering if it is at least theoretically possible for Ethereum to have a language that is loose/weak typing. From what I've seen all the languages on Ethereum are static typed. My understanding ...
zunior's user avatar
  • 1,312
2 votes
2 answers
351 views

What is standard practice to cast msg.sender to "payable"?

Introduction I am working on a bounty contract. Here is the function for somebody answering the bounty. I am trying to figure out when it is better to cast to payable, it seems intuitively that always ...
Victor Forissier's user avatar
0 votes
1 answer
421 views

having trouble declaring a fixed size byte array constant

I was able to declare this constant as a bytes object, but am trying to compress it for efficiency, and I'm getting this error message: Only constants of value type and byte array type are implemented....
scheherazhaad's user avatar
0 votes
1 answer
1k 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 ...
ransika ranasinghe's user avatar
2 votes
0 answers
604 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 ...
Duncan Townsend's user avatar
0 votes
1 answer
412 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 ...
David's user avatar
  • 153
1 vote
1 answer
79 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 ...
VitoCK's user avatar
  • 161
2 votes
2 answers
136 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 ...
Paul Razvan Berg's user avatar
0 votes
1 answer
139 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?
user97024's user avatar
1 vote
2 answers
94 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: ...
Abdulhakim's user avatar
1 vote
1 answer
94 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 ...
jmsandiegoo's user avatar
0 votes
1 answer
359 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 ...
Ryan Detzel's user avatar
0 votes
1 answer
32 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 ...
Rony Tesler's user avatar
0 votes
1 answer
827 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 ...
daveaneo's user avatar
0 votes
1 answer
671 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(...
MShakeG's user avatar
  • 1,735
1 vote
3 answers
2k 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 ...
Falcon Stakepool's user avatar
1 vote
1 answer
623 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)?
Friedrich Coen's user avatar
1 vote
1 answer
1k 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)...
BarefootDev's user avatar
1 vote
1 answer
604 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. ...
jkiles's user avatar
  • 95
0 votes
1 answer
86 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; } ...
Fly's user avatar
  • 101
0 votes
1 answer
400 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 ...
David Ochoa's user avatar
1 vote
1 answer
543 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 ...
Ahmed Ihsan Tawfeeq's user avatar
1 vote
2 answers
1k 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; ...
paul243's user avatar
  • 23
2 votes
1 answer
479 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: ...
Mikhail Janowski's user avatar
0 votes
2 answers
917 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
David Callanan's user avatar
1 vote
1 answer
236 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 ...
YulePale's user avatar
  • 1,853
0 votes
1 answer
104 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....
wehnsdaefflae's user avatar