Questions tagged [uint256]

The tag has no usage guidance.

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

Performance and Gas Implications: uint vs int in Solidity Memory Variables

I am working on a Solidity smart contract and am considering the use of uint and int data types for memory variables. I have specific use-cases like reverse looping, where using int seems to produce ...
Eugene1111's user avatar
0 votes
1 answer
75 views

Updating values that are packed inside a uint256

I recently learned about packing smaller uints inside bigger uints. for example: uint64, uint64, uint8, uint120 all packed into a single uint256. my question is, how can i update one of the values ...
Nolan Jannotta's user avatar
1 vote
0 answers
25 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
1 vote
1 answer
82 views

Does casting a Keccak256 hash to a uint256 increase likelihood of a collision?

I have a smart contract with 50+ trillion possible NFT names that could be minted (all have unique names), is there any chance that this method could cause a collision of token ID's? - uint256 tokenID ...
Vince Reid's user avatar
0 votes
0 answers
14 views

Gas fees differ for updating different values?

I've did some gas efficiency tests on the testnet and wonder why the following is the case... Updating values can be done with both of these methods: x += y; /// or /// x = x + y; For mappings, like ...
Andy's user avatar
  • 185
4 votes
2 answers
105 views

Why uint8 for decimals in ERC20 tokens?

Is there a specific reason why pretty much everyone uses uint8 for the decimals in ERC20 tokens? I would get it if it was to limit the size, because the decimals will never be big enough to exceed the ...
Andy's user avatar
  • 185
0 votes
1 answer
425 views

go ethereum bigint and unit256

Golang can only handles up to 64 int however ethereum contract call can return uint256 for example https://eips.ethereum.org/EIPS/eip-20 balanceOf method. Does https://github.com/ethereum/go-ethereum ...
Min Hsiu Hsieh's user avatar
1 vote
1 answer
111 views

object returned for uint256 return value

I implemented a method to retrieve a price for a currency via some chainlink price feed. This price is casted to an uint256. But if I call this method via etherscan it does not show a number, but just ...
jan's user avatar
  • 111
1 vote
0 answers
82 views

ERC1155 ID - how to handle BigNumber?

I'm exploring Gnosis conditional tokens (which are adapted ERC1155). The _mint method in ERC1155 requires an id that is uint. Gnosis has a method called getPositionId which converts a keccak256 hash ...
alpo's user avatar
  • 164
0 votes
1 answer
15 views

I get this type error question while writing my solidity Programming

//SPDX-License-Identifier:MIT pragma solidity 0.6.1; contract ExampleMapping1{ mapping(uint => string) names; struct Name{ string yourName; } function MyNames(uint _rNo,...
Akhil Vinayak P's user avatar
0 votes
2 answers
275 views

How to represent uint256 in EVM using Golang?

I am asked to build a small EVM with few instructions using Golang. What I am confused about is how to represent the uint256 data type? Because Golang supports at most uint64 for integer type. What I ...
Ahmet Yazıcı's user avatar
1 vote
1 answer
34 views

Transalte Assembly(Solidity)

I want translate code to assembly, but i don't understand , how i can get data from string ( or bytes) Example String: 123 --> uint 123 for (uint256 i = 0; i < bytes(_str).length; i++) { ...
Kilo Arms's user avatar
0 votes
2 answers
32 views

Uint Variables Division result in 0 (Point Number)

I am trying to calculate a proportional reward by using the percentage of a wallet balance compared to a token's total supply. uint256 reward = walletBalance / totalSupply * rewardPool However, the ...
noob's user avatar
  • 11
0 votes
2 answers
92 views

Chainlink VRF V2 - TypeError: Wrong argument count for function call: 2 arguments given but expected 1

I tried to use Chainlink VRF V2 on my contract but got errors like shown picture below. Does anyone know how to solve this? My Chainlink VRFV2 Oracle function /// @dev chainlink oracle function to ...
BadGenius's user avatar
1 vote
1 answer
75 views

Byte32 to uint and then back to byte32

I have to bitpack two uint128 values into a uint256, then get back the two original uint128s. To encode the values I'm using: function encode256(uint128 a, uint128 b) pure public returns (uint256) { ...
Alexis's user avatar
  • 149
0 votes
1 answer
169 views

What is the difference between string and uint(int) in solidity?

// SPDX-License-Identifier: MIT pragma solidity 0.8.16; contract test7 { function getNum() public pure returns(uint256[4] memory,string memory) { string[4] memory _a = ['1','2','3','4']; ...
imelon2's user avatar
  • 455
0 votes
0 answers
26 views

How do I remove decimals from a uint256 [duplicate]

I am calculating a buyPrice that has a factor of 1.2 times the normal price. To do this I get the token price and multiply it by 1200000000000000000 (18). It looks something like: uint256 buyPrice = ...
Pim Hakkert's user avatar
0 votes
1 answer
90 views

Error when trying to operate on 2 uint256[] arrays

I have the following snippet uint256[] public s_results = [84080469561607224741111096759358273404425425552033897563872674800638878201820, ...
momoja's user avatar
  • 239
0 votes
2 answers
314 views

Converting Chainlink oracle response (int256) to uint256

I am trying to get the latest ETH price from the Chainlink priceFeed contract. The response shows up like this 171617306235 as a BigNumber. So there is a couple of issues for me to be solved. 1 - My ...
Sina Rahimi's user avatar
0 votes
1 answer
86 views

Convert bytes to base 10 number by keeping digits in tact

I have a very weird use case. Tl;dr I'm trying to convert a bytes16 to a base 10 integer by keeping the digits in tact. i.e 0x00000000000000000000000002987391 should become 2987391
BonisTech's user avatar
  • 536
0 votes
0 answers
121 views

How to get Uint256 from bytes

I'm learning about NFT with Solidity, and implanted some basic contract as follows. NFTToken Contract: // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/...
Div's user avatar
  • 361
0 votes
1 answer
1k views

How To Convert Hex String to A Uint in Solidity ^8.0.0

I have this function that converts a unit to a hex string: function uintToHexString(uint i) public pure returns (string memory) { if (i == 0) return "0"; uint j = i; uint length; ...
Jim's user avatar
  • 173
0 votes
1 answer
507 views

Where is the single-parameter version of function sub() defined in SafeMath?

I'm going through the Ethernaut challenges to learn Solidity, and in challenge 3 ("Coin Flip"), they show the following code which subtracts 1 from the current block number: I assumed that ...
RSW's user avatar
  • 139
0 votes
0 answers
60 views

Truffle with weird behavior dealing with uint type of variables

I´ve spent a couple weeks try to understanding what was heppening. The same solidity code worked great in REMIX but not in Truffle/Ganache. Let´s me explain. I wrote a code bases on Openzeppelin, but ...
p3cardoso's user avatar
0 votes
1 answer
208 views

Contract instance in console - return object when expecting return uint [duplicate]

I am running functions using an instance of a contract in a browser console. When I call a function that is supposed to return something, I get a return object, with a "words" property that ...
Alex Nedop's user avatar
0 votes
1 answer
622 views

What is the return of uint(keccak256(_str));?

I'm doing the chapter 1 of the crypto zombies course. uint id = zombies.push(Zombie(_name, _dna)) - 1; NewZombie(id, _name, _dna); } function _generateRandomDna(string _str) ...
disqid's user avatar
  • 13
2 votes
1 answer
648 views

Is it better practice to use smaller uint sizes when applicable?

My understanding of uint sizes is that smaller sizes will decrease gas costs. In my current dapp I'm building, I am dealing with time, for which it seems that uint32 will be plenty for my purposes (...
quantummidget's user avatar
0 votes
1 answer
697 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
269 views

Why does uint 0 - 20 not cause an underflow?

I expect this to underflow and become a big number. But calling this method I get a: MetaMask - RPC Error: execution reverted function over() public pure returns (uint) { uint a = 0; return ...
user1099123's user avatar
0 votes
1 answer
99 views

Initializing uint array produces big number error

Very beginner question! I am having a really tough time initializing an array of uints. I have a test contract that consists of 1 line to test this and though it compiles, when I view the data in the ...
Travis Felker's user avatar
1 vote
1 answer
6k 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
7 votes
2 answers
926 views

Why do reputable ERC721 contracts use uint256 so often?

So I learned very early in my Solidity reading that we should be smart about memory allocation, specifically regarding the proper usage of uint variables. This means properly assigning uint8, uint16, ...
Doug's user avatar
  • 173
0 votes
1 answer
1k views

Error: overflow

I am trying to mint a nft token from my test using a tokenId number like this: 123456789123456789123456 a very big number, but when I try to mint I get the following error: { Error: overflow (fault=&...
Jean's user avatar
  • 117
1 vote
1 answer
406 views

tokenId (uint256) not returning correctly

In my tokenURI function, I have it setup to return the tokenId that is being called for, but when I run the method I get a symbol. function tokenURI(uint256 _tokenId) public view virtual override ...
hear har's user avatar
0 votes
1 answer
24 views

compare uint from datestamp always return true

function testDate(uint date1,uint date2) public returns (bool) { require(date1 == date2,'not same date') return date1 == date2; } let res = await TestSol.testDate.call(‘1630972800’,‘1631145600’)...
Shen Yang's user avatar
1 vote
1 answer
611 views

Why do you have to wrap a uint() around a number when dividing it and there is a reminder?

Why do you have to wrap a uint() around a number when dividing it and there is a reminder? When I do as the code shows below I get no error and the code works fine. function doMath() public pure ...
YulePale's user avatar
  • 1,823
0 votes
1 answer
27 views

smart contract information issue

Hi I was scammed by troncase, I want to know how to get my original staking out of the smart contract. it is asking me for a userAddress_address, last_uint256, first_uint256 What do i type in those ...
Melshun Mclemore's user avatar
1 vote
1 answer
133 views

Why does return ((2**256-1)+5)%15 not overflow?

I am writing a smart contract that has to be able to compute the sum of two numbers, modulo another number, where the sum might overflow 2**256-1. I'd write this as (a%c+b)%c, to prevent overflow. I ...
Johan's user avatar
  • 13
0 votes
1 answer
834 views

How is uint8 calculated from a uint256 conversion in Solidity?

I'm aware that a conversion from uint256 to uint8 looks like this: uint8(A_UINT256_NUMBER) But how is a uint8 calculated from uint256? There's definitely loss of data, but I assumed that converting ...
Pottedtree's user avatar
2 votes
1 answer
200 views

How to add three numbers using safemath?

I know this might sound obvious but in solidity you can never be too sure. Let us say I have three numbers 5, 7 and 8. Can I add them like so: using SafeMath for uint256; 5.add(7.add(8)); // or even ...
YulePale's user avatar
  • 1,823
1 vote
1 answer
8k views

How to send uint256 and Address types to Smart contract in JavaScript web3/ethers?

Im trying to send a query to Pancakeswap's router function getAmoutsOut here the code for importing the contract using ethers ABI: const router = new ethers.Contract('...
Aaron Klich's user avatar
2 votes
1 answer
488 views

How to get the first digit of a uint256

I want to check, if the first digit of a uint256 is equal 5. I therefore do the following: function _numDigits(uint256 _number) internal pure returns (uint8) { uint256 number = _number; uint8 ...
user66732's user avatar
  • 435
2 votes
0 answers
262 views

What is the neatest way to get hold of max uint256 in assembly?

Since Solidity v0.6.8, the neatest way to get hold of max uint256 in Solidity is this: uint256 foo = type(uint256).max; Is there something like that for Yul? I couldn't find anything in the docs. I ...
Paul Razvan Berg's user avatar
4 votes
1 answer
324 views

How to take the average of two uint256s without overflowing?

Say you have two uint256 numbers, x, and y. One way to calculate the arithmetic average between them is this: function avg(uint256 x, uint256 y) external returns (uint256 result) { result = (x + y)...
Paul Razvan Berg's user avatar
0 votes
0 answers
254 views

String to float maintaining decimal places

I've seen some thread already however I haven't found anywhere a way of converting a string number to float number and maintaining the decimals. ie "27.546" to 27.546
spyrAlex's user avatar
0 votes
0 answers
97 views

Acess position in array vs Access key in mapping (uint IDs) - What's the efficient way?

I have a doubt about efficiency in solidity, when searching in lists of integer values, in mapping vs array. Array Imagine that I use the array position as element ID, and the content as the value, as ...
Alexander Herranz's user avatar
1 vote
0 answers
403 views

Checking if an item present in an array in Solidity

I want to check whether a specific item is included in an array or not. For example, consider the following array. uint[] a = [1, 2, 3, 4] Is there any way that I can get true if I have given 4, and ...
MikhilMC's user avatar
  • 133
2 votes
1 answer
402 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
1 vote
1 answer
496 views

Create map of existing objects in mint function for a smart contract

I'm really new to solidity and there is still alot I dont fully get. I have created this smart contract. I am getting an error while performing a test stating that the id to be set by the push cant be ...
Juan Carlos Garfias Tovar's user avatar
0 votes
0 answers
44 views

Negative integer function

I have the following problem, one of my function has a variable where the uint can be negative but I don't know of that before the user enter in the form the integer. How do I settle this problem ? ...
Tameiki's user avatar