Questions tagged [solidity]

Solidity is a language for smart contracts for blockchain technologies like Ethereum. It is designed to compile code for the Ethereum Virtual Machine. Use this tag for questions about programming smart contracts using the Solidity language.

Solidity is an object-oriented language whose syntax is similar to that of ECMAScript, but with static typing, and it is designed to compile to code for the Ethereum Virtual Machine for use in smart contracts in blockchain technologies.

6642 questions
17
votes
2 answers

Solidity, Solc Error: Struct containing a (nested) mapping cannot be constructed

I am using Solc version 0.7.0 installed by npm. When I try to create a Struct that contains mapping, I received an error: "Struct containing a (nested) mapping cannot be constructed." Please check the code: // SPDX-License-Identifier: MIT pragma…
coding
  • 627
  • 7
  • 20
17
votes
4 answers

UnhandledPromiseRejectionWarning: Error: The contract code couldn't be stored, please check your gas limit

I am trying to deploy my simple solidity smart contract onto the Rinkeby Network but I keep getting the error: UnhandledPromiseRejectionWarning: Error: The contract code couldn't be stored, please check your gas limit. My solidity code is…
Jason
  • 1,059
  • 1
  • 13
  • 32
17
votes
2 answers

Is it possible to modify a variable value from another contract?

I could get the information about access another contract's variable from here But I couldn't find how to modify another contract's variable. Here is the example of contract A, contract A { uint public target; } And this is the example of…
Henry Kim
  • 575
  • 4
  • 19
17
votes
4 answers

Is there a pop functionality for solidity arrays?

I have used solidity to push data into an array. Is there a similar function for pop ? string[] myArray; myArray.push("hello") What is the best solution for this ? How do I delete an element in a dynamic array in solidity ?
Suraj Kohli
  • 547
  • 2
  • 5
  • 11
17
votes
2 answers

Calling external contract in solidity dynamically

I am trying to make a contract have a function that is capable of calling functions of another contract. The key part of my goal is that the contract should not be able to be deployed without any import statements and will not know the name of the…
GK1
  • 447
  • 1
  • 5
  • 11
17
votes
2 answers

Division in Ethereum Solidity

I am creating a contract that issues tokens. I would like an account that holds tokens to be able to check what percentage they own out of all the tokens issued. I know that Ethereum has not implemented floating point numbers yet. What should I do?
GK1
  • 447
  • 1
  • 5
  • 11
17
votes
2 answers

Getting the address of a contract deployed by another contract

I am trying to deploy a contract from another factory contract and then return the address of the newly created contract. The address it returns however is the transaction hash not the contract address. I believe this is because the contract is not…
Joe
  • 321
  • 1
  • 2
  • 12
17
votes
2 answers

How do I initialize an array in a struct

I have a struct Purchase in which I'm putting an array of payments. However, when I try to add the new payments array in my makePayment method I get an error back from the solidity compiler: "Internal compiler error: Copying of type struct Payment…
unflores
  • 1,764
  • 2
  • 15
  • 35
16
votes
5 answers

TypeError: Data location must be "memory" for parameter in function, but none was given

I tried to compile my code, but I got the following error: TypeError: Data location must be "memory" for parameter in function, but none was given my code: pragma solidity ^0.5.0; contract memeRegistry { string url; string name; …
15
votes
5 answers

Failing to compile multiple Solidity versions

I'm trying to compile (through Hardhat) a contract that imports several interfaces with different Solidity versions but I'm getting the following error: Error HH606: The project cannot be compiled, see reasons below. These files and its…
dNyrM
  • 545
  • 1
  • 4
  • 17
15
votes
1 answer

How do you compare strings in Solidity?

I would assume comparing strings would be as easy as doing: function withStrs(string memory a, string memory b) internal { if (a == b) { // do something } } But doing so gives me an error Operator == not compatible with types string memory…
Evan Conrad
  • 3,993
  • 4
  • 28
  • 46
15
votes
3 answers

Ethereum Solidity - Does require() use any gas?

Google has failed to give me an concrete answer, does using the require() function in Solidity use up any gas? Even if the statement in the function is evaluated as true?
mrsulaj
  • 398
  • 3
  • 12
14
votes
3 answers

How to find out in advance the address of the smart contract I am going to deploy?

I have a Solidity smart contract ContractFactory which I am deploying on RSK and developing in Hardhat. ContractFactory has a deploy function which produces new Child smart contracts. ​ // SPDX-License-Identifier: MIT pragma solidity…
Owans
  • 1,037
  • 5
  • 14
13
votes
7 answers

The transaction declared chain ID 5777, but the connected node is on 1337

I am trying to deploy my SimpleStorage.sol contract to a ganache local chain by making a transaction using python. It seems to have trouble connecting to the chain. from solcx import compile_standard from web3 import Web3 import json import os from…
E_charles
  • 133
  • 1
  • 4
13
votes
1 answer

ValueError: Method eth_maxPriorityFeePerGas not supported, web3.py with ganache

I'm running the following code with web3.py: transaction = SimpleStorage.constructor().buildTransaction( {"chainId": chain_id, "from": my_address, "nonce": nonce} ) And I am running into the following error: Traceback (most recent call last): …
Patrick Collins
  • 5,621
  • 3
  • 26
  • 64