Questions tagged [data-types]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
20 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
11 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
18 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
16 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
34 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,633
1 vote
1 answer
50 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
65 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
277 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
3 votes
2 answers
1k 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
185 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
175 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
  • 350
1 vote
1 answer
348 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
136 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
495 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
602 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
286 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
342 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
345 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
937 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
566 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
391 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
77 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
127 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
108 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
88 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
90 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
317 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
30 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
764 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
647 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,633
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
606 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
585 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
  • 85
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
375 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
534 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
469 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
893 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
227 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,843
0 votes
1 answer
102 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
0 votes
1 answer
512 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 ...
Divya Singh's user avatar
2 votes
0 answers
430 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 { ....
Paul Razvan Berg's user avatar
4 votes
1 answer
1k 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,...
António Gonçalves's user avatar
1 vote
1 answer
2k 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 ...
Alberto Molina's user avatar