Questions tagged [solidity-0.8.x]

The tag has no usage guidance.

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

Is the possible to store reference of struct inside the mapping array

I have the following code contract SampleContract { struct GameData { uint256 game_id; address player1_wallet_address; address player2_wallet_address; ...
0
votes
0answers
15 views

What is the difference between function has() and function hasRole()?

solidity ^0.4.24; function has(Role storage role, address account) internal view returns (bool) { require(account != address(0)); return role.bearer[account]; } vs solidity ^0.8.0; function ...
1
vote
1answer
26 views

Why is solidity asking me to restrict state modifier function to view?

Version 0.8.7 Solidity is complaining that several state modifier functions can be restricted to view, such as: function updateStruct( uint256 dummyParam ) public onlyOwner { DummyStruct ...
0
votes
0answers
39 views

Transaction error. Exception thrown in contract code. mint function

We have been trying to connect the UI with the smart contract in order to carry out a mint functionality of a nft. But have been facing this error (Transaction error. Exception thrown in contract code)...
0
votes
1answer
42 views

truffle test - Error: Contract has not been deployed to detected network (network/artifact mismatch)

As I excessively read all posts given and none solved my problem I'm opening this thread. Please don't consider every test for useful as I'm in the development of useful tests. As mentioned it is ...
0
votes
1answer
81 views

Get all tokens owned by an address under the same ERC1155 contract

I am making an ERC 1155 contract and it is a mixture of NFTs and FTs, my intention is that from a token id forward, the user only be able to own one of the token, something like the minting below: ...
0
votes
0answers
16 views

Dynamic asset price calculator in solidity

My Token struct looks like this. struct Token { uint256 value; // Price of token in wei uint256 parts; // set to 10 ** 18 } Now: Anyone can create a Token and set its value Other users can ...
0
votes
0answers
32 views

Error in testing contract with javascript on truffle

I'm trying to test a contract multiple times on truffle using javascript. The first test runs just fine, but the second gives me error no matter what's inside of it. Here is my full testing code: ...
0
votes
1answer
37 views

ERC721Enumerable totalSupply() returns 0 on rinkeby. solidity v0.8.4

I'm deploying an ERC721Enumerable token on rinkeby testnet and when I request the totalSupply() function (Counters doesn't work either) I get a return of 0.. even though my tokens show up on etherscan ...
0
votes
0answers
86 views

What is the purpose of "unchecked" in Solidity?

According to Solidity documentation: Prior to Solidity 0.8.0, arithmetic operations would always wrap in case of under- or overflow leading to widespread use of libraries that introduce additional ...
0
votes
1answer
39 views

Transaction reverted by the EVM and I cannot see the reason

I am new to blockchain technology and ethereum contracts development and I cannot track down the bug I have in my first contract code. This is an ERC-721 (NFT) contract type. NFT is a reward for ...
0
votes
1answer
50 views

Exception When Calling Function In a Library that Returns an Array

I have a solidity library that has a public function and it's returning a uint8[] array. pragma solidity ^0.8.4; library LibA { function getArray() public pure returns (uint8[] memory) { ...
0
votes
1answer
34 views

Cannot import most libraries out there due to their compiler version being too old

My Contract has pragma solidity ^0.8.0; but I am using this library to be able to split strings that uses pragma solidity ^0.5.0;. Changing this line alone wont fix the issue, it will create new ones (...
0
votes
1answer
36 views

How can I fix an Invalid implicit conversion from int256 to uint256 requested

I'm creating a modified version of Sushiswap's Masterchef V2 contract using solidity 0.8.4. user.rewardDebt = user.rewardDebt.add( int256(_amount.mul(pool.accAmountPerShare) / accHarpyPerBlock) ...
0
votes
1answer
29 views

ERC20 Token Transfer Issue

I have a test token (ERC20) deployd on ETH test network (Kovan) The token was deployed using Unicrypt tool So far everything ok, but the issues is how can i transfer tokens from an outside smart ...
0
votes
0answers
11 views

ParserError: Expected primary expression when using var

I am trying to create a struct and add mapping in such a way that it can be retrieved later on using its address using the below code. pragma solidity ^0.8.0; contract Courses { struct ...
0
votes
1answer
29 views

Delete mapping in solidity

mapping(uint => address) public Players; can anybody help me how can I delete Players mapping. I wrote a lottery contract and I need to remove this mapping to reuse the contract. I try this code ...
0
votes
1answer
34 views

Overriding a function does not work as expected

I'm not sure I understand how overriding a function works in solidity. I am working on an ERC721 token based on the OpenZeppelin implementation. OpenZeppelin's ERC721.sol contains the following ...
0
votes
1answer
29 views

Iterate through a sequence of numbers like an array

I would like to be able to send a fairly long (uint256) sequence of numbers from web3 to solidity and then iterate through the sequence in my solidity function. Web3 code would be something like: ...
0
votes
0answers
20 views

How do i get the price of an erc20 token from solidity smart contract [duplicate]

I'm building a dapp, i'm trying to get the erc20 token price in usd from my smart contract how do i go about this? this is very necessary as smart contracts cannot read from outside networks. I don't ...
0
votes
1answer
50 views

How to create nested data structures Solidity 0.8

I'm a JS dev fairly new to solidity. I couldn't find something to cover this when dealing with custom data. I want to create a function that I can use to push data into the contract. I'm trying to get ...
0
votes
1answer
45 views

How to store mapping with inline assembly?

I have a special needs, store the mapping with assembly code. thank you very for everyone who can response this question. for example: contract assemblyMappingTest{ mapping(address => uint) ...
1
vote
1answer
23 views

How do I initialise a dynamic array in a solidity struct for every newly created struct?

contract Foo { struct Bar { address owner; uint[] x; } mapping( uint => Bar) bars; function foobar(uint index) public { Bar memory b = bars[index]; ...
0
votes
1answer
21 views

Keep an old Solidity version token, or update it for new contracts development

I am working in a project with an ERC20 token generated with Solidity 0.4 (but for the moment, all the tokens are in the owner's address). Community already knows this token address, and knows that it ...
0
votes
0answers
18 views

How to take input in remix for 2D array in solidity?

My Contract code contract SomeTokenVesting { mapping(address => uint256[6]) public vestingAmounts; constructor() { // some code } function addSomeBeneficiaries(address[] ...
0
votes
1answer
80 views

Can't Call Payable Function from Web3

I am trying to call a public payable function from my smart contract (^0.8.0) in a ropsten testnet function purchaseCardPack() public payable { require(msg.value == cardPackFee, "...
0
votes
1answer
167 views

solcx.exceptions.SolcError: Unknown key "*"

I'm learning how to deploy a smart contract using a Python script and I keep getting the following error: > py deploy.py INFO: Could not find files for the given pattern(s). Traceback (most recent ...
0
votes
0answers
28 views

Gas Limit Drops to Zero for Internal Transaction

I've deployed a contract to Rinkeby involving a few different interfaces I've written. This result in a fair number of transactions occurring behind the scenes with different contracts. There is a ...
0
votes
1answer
90 views

How to convert in-memory static array to calldata static array?

I have a contract called Erc20Recover in which I have the following function: pragma solidity >=0.8.0; contract Erc20Recover { function _setNonRecoverableTokens(IErc20[] calldata tokens) ...
0
votes
1answer
195 views

How to call a fallback function in remix

I have the below code in remix. I remember the remix had the "fallback" button to check the fallback method. I am back after long time. I do not find the "fallback" button. I ...
1
vote
0answers
47 views

How to write Test case for Internal functions in solidity which inherits the ERC721

**This is my Smart Contract code which has inherited the ERC721 and I want to write the test case for _setTokenURI ** contract ProductNFT is ERC721 { constructor () public ERC721(_tokenName,...
5
votes
2answers
180 views

How to bubble up a custom error when using DELEGATECALL?

Solidity v0.8.4 introduced custom errors: error Unauthorized(); Say I have contract A which delegate calls to contract B. The latter reverts with the custom error defined above. How can I bubble that ...
0
votes
2answers
127 views

How to write test case for the require function

**Contract** contract ProductNFT is ERC721{ uint public totalSupply; address public wadmin; address public brand; address public designer; ...
0
votes
0answers
27 views

Gas Cost is increasing exponentially with each iteration in loop -Ganache

I ve written a function to calculate factorial of any number in view function, I know view function calls is free from outside the evm but was just trying to calculate gas usage for that. and what I ...
0
votes
1answer
45 views

How to withdraw ether from reference of a smart contract?

//SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract acceptETH { address public owner; uint256 public price; mapping(address => uint256) balances; constructor (){ ...
1
vote
1answer
112 views

How to send and receive value using ERC-1155

I am relatively new to solidity and blockchain. I want to develop a smart contract that sends values and another contract that accepts one using ERC-1155 tokens.Can any of you please help me out with ...
1
vote
2answers
57 views

How to add modifier to public state variable?

I have a contract that looks like this pragma solidity >=0.7.0 <0.9.0; contract SomeContract { uint256 public id; address public creator; enum Status {ACTIVE, INACTIVE} ...
0
votes
1answer
26 views

Not able to use variable i for any operation inside for loop

I am new to solidity and stucked at very strange issue. I am not able to use variable i for any type of operation inside for loop. for (uint256 i; i < data.numPoints; i++) { //uint256 xx = ...
3
votes
2answers
72 views

Why does Openzeppelin's CountersUpgradeable library wrap arithmetic in an unchecked block?

I was reading through the source code for Openzeppelin's CountersUpgradeable library v4.3.0 and realised that the arithmetic operation in the increment / decrement functions is wrapped by an unchecked ...
0
votes
1answer
336 views

Decode raw data within Solidity

If I only have the raw input data of a contract call, what would be the best way to decode it into readable form within Solidity? "[INPUT]":"...
0
votes
1answer
27 views

Alter data in a struct using solidity

I am trying to create a students record using remix I am trying to replace data from an already stored struct. How can I do that? Below is my implementation untill now. contract StudentContract { ...
0
votes
0answers
197 views

Error in ERC20 Token transfer from Crowdsale contract

These are the steps I followed: approve admin for 2 B spending. transfer 2 B out of 10 B to MyCrowdsale contract using transferFrom() function approve 2 B spending for MyCrowdsale contract set the ...
0
votes
1answer
96 views

Metamask Not Showing Amount Transferred from Contract in Activity Log

I've written a smart contract which, like many smart contracts, has a withdrawal message. This withdrawal message will liquidate all holdings of msg.sender and transfer holdings to them. The actual ...
0
votes
0answers
14 views

Function doesn't run after receiving custom token

I have an issue with my smart contract when it receives a custom token: uint256 private privatePrice = 20; uint256 public totalCollected; uint256 public previousCollected = 0; uint256 public ...
0
votes
0answers
17 views

Solidity uint256 equivalence bug during integration tests

Only happens on about 20% of runs. (the numbers are random each run, but they always equal).
0
votes
0answers
192 views

How to prevent timeout on Solidity contract (not on tests or deployment config)

Consider the following function which is our current workaround to calculate the power of fractionals without overflowing (if you know a better one please let me know in the comments): function power(...
2
votes
0answers
58 views

Smart contract function signature only 1 byte

I have noticed some contract calls only contain the function signature in the 1st byte of the input data. For example: ...
0
votes
1answer
85 views

Solidity 0.8.x test today's date from block.timestamp

I want to make sure that the block.timestap that keep on running is represent today's date. I can get from this code but not really sure is this the right way. function isTodayDate() view public ...
0
votes
0answers
263 views

Minting ERC20 token fails because of zero address even though address is non-zero

I'm building an ERC20 token using OpenZeppelin's ERC20 contract. My token constructor looks like this: constructor() ERC20( "Token", "TKN" ...
0
votes
0answers
32 views

Enum in interface

Is it possible by creating any function in the interface user can declare his own set of enum states? Let's say for example:- I want to create an interface using which the user can declare his own set ...