40 votes
Accepted

Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient

This is saying that adding public - a visibility specifier - to a constructor has no effect. Constructors are run only once, when the contract is initially deployed. They can't be called at a later ...
Richard Horrocks's user avatar
19 votes
Accepted

Deploying contract with constructor arguments via Geth RPC

It is quite complicated to get this correct, but here's some information on how to work it out. I'm using a simple contract as an example: pragma solidity ^0.4.2; contract Test { uint256 public ...
BokkyPooBah's user avatar
  • 40.3k
16 votes
Accepted

Invalid implicit conversion from address[2] memory to address[] memory requested

It is not possible to cast between fixed size arrays and dynamic size arrays. You have to create a temporary dynamic array and copy the elements. address[] memory t = new address[](2); t[0] = ...
Ismael's user avatar
  • 30.5k
14 votes
Accepted

Should the constructor function be public?

When you are trying to compile contract with private constructor, for example this one: pragma solidity ^0.4.15; contract PrivateConstructor { string public title; function ...
Dmytro Zarezenko's user avatar
13 votes
Accepted

Is address(this) a valid address in a contract's constructor?

Yes, a contract constructor can access it's own address. This code works just fine to both log the address, and set it in storage: pragma solidity ^0.4.0; contract Test { address public ...
maurelian's user avatar
  • 3,211
12 votes

Contract inheritance

The accepted answer by @shawn-tabrizi is a good example of how to set up inheritance properly but the reason you got the error is different and I want to share for anyone else that finds this answer ...
Justin Harris's user avatar
12 votes

Passing constructor arguments to the CREATE assembly instruction in solidity

This worked for CREATE2. Maybe it also works on CREATE? abi.encodePacked(bytecode, abi.encode(arg1, arg2)) Example (CREATE2) pragma solidity ^0.5.11; contract Wallet { address public owner; ...
tsknakamura's user avatar
12 votes

Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient

remove public from constructor, that's all. eg.- constructor( . . . ) { . . . } why? its constructor, not a function. So solidity compiler says : "u don't need to make constructor public, its ...
aakash4dev's user avatar
11 votes
Accepted

How to manually initialise an array in Solidity?

You can't assign a value to an array of size 0, you need to have enough space to write your value. It is true, you declared a variable size array but you still need to tell the VM to increase the ...
Giuseppe Bertone's user avatar
11 votes
Accepted

What is the significance of making constructor payable?

payable means that you can transfer ether with the transaction. If the contract is designed that it needs an ether deposit on construction, then you can not hard code this. You have to allow the ...
ivicaa's user avatar
  • 7,519
10 votes

Should the constructor function be public?

Update for Solidity ^v0.7 The constructor visibility has been removed from Solidity. You have to remove the "public" and the "internal" modifiers from your constructors. Read more ...
Paul Razvan Berg's user avatar
9 votes

Is address(this) a valid address in a contract's constructor?

The detail of contract creation are in Yellow Paper section 7, but it is too technical to quote here. But in section 7.1. Subtleties is more quotable Note that while the initialisation code is ...
Ismael's user avatar
  • 30.5k
9 votes
Accepted

Does Solidity support passing an array of strings to a contract's constructor yet?

You can actually use an array of byte32 as an argument to a solidity function as with this constructor function: constructor(bytes32[] memory proposalNames) public { chairperson = msg.sender; ...
faint-hearted-fool's user avatar
7 votes
Accepted

Contract inheritance

I believe this exact scenario is covered by the Solidity: Inheritance > Arguments for Base Constructors Here is the example they give: pragma solidity ^0.4.22; contract Base { uint x; ...
Shawn Tabrizi's user avatar
6 votes

Passing constructor arguments while deploying contract from byte code

If you look at Web3's documentation, you can get the full deployment bytecode with: var bytecodeWithParam = MyContract.new.getData( param1, param2, { data: compiledByteCode }); It is ...
Xavier Leprêtre B9lab's user avatar
6 votes
Accepted

How are the arguments of the constructor encoded in the contract creation transaction?

According to the Ethereum Yellow Paper (section 4.2), the contract creation transaction does not have a data byte array where the arguments to method calls are placed. The contract creation only has ...
Thorkil Værge's user avatar
6 votes
Accepted

How to verify a contract having constructor arguments?

You need to correctly ABI-encode constructor arguments. You can easily do this with online tool https://abi.hashex.org. Just paste in abi to automatically parse constructor parameter types or add them ...
Gleb Zykov's user avatar
6 votes
Accepted

How to get the actual runtime bytecode from creation bytecode and constructor arguments without deploying

This GitHub issue helped me find the answer. Basically what I needed can be achieved with the ethereumjs-vm module: const VM = require("ethereumjs-vm").default; const BN = require("bn....
FabijanC's user avatar
  • 111
6 votes

Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient

In v0.5.0 it was mandatory to add visibility to the constructor. This is from the docs of the breaking changes in v0.5.0: https://docs.soliditylang.org/en/v0.7.0/050-breaking-changes.html#explicitness-...
BonisTech's user avatar
  • 634
5 votes

Should the constructor function be public?

A constructor can be internal or public; however, if the constructor has a 'payable' modifier, then the constructor can only be public. Regarding internal visibility, it makes it possible for an ...
b1programmer's user avatar
5 votes
Accepted

Constructor auto generation and property visibility

Good Question! Lets explore the constructor inheritance: Lets look at the following example: import "dapple/test.sol"; contract A { bool aHit; bool public aPublicHit; bool public ...
Denis's user avatar
  • 901
5 votes

Dynamic Arrays in solidity Structs

From https://solidity.readthedocs.io/en/v0.4.21/types.html#array-literals-inline-arrays: Note that currently, fixed size memory arrays cannot be assigned to dynamically-sized memory arrays, i.e. the ...
user19510's user avatar
  • 27.9k
5 votes
Accepted

How does a contract's constructor work and load input values?

In Solidity, arguments to the constructor are ABI encoded and appended to the compiled bytecode. The arguments are copied to the EVM memory using CODECOPY. In Etherscan, you can see that the last ...
eth's user avatar
  • 85.5k
5 votes

Ethers js deploy contract with balance, payable constructor

Just change initialBalance to { value: initialBalance } const deployedContract = await myContract.deploy({ value: initialBalance }); The deploy function takes constructor arguments followed by an ...
Soham Zemse's user avatar
  • 2,016
4 votes
Accepted

Constructor not working properly

It's a critical bug in solc. Ref: https://github.com/ethereum/solidity/issues/485
q9f's user avatar
  • 32.9k
4 votes

Mapping member isn't initialized when creating a struct

Mapping is a really particular type and it's different from a simple array. From the official documentation: Mappings can be seen as hashtables which are virtually initialized such that every ...
Giuseppe Bertone's user avatar
4 votes
Accepted

Contract created by another contract and exceptions

1. Yes B will not be created if the transaction containing the creation of B has an exception. Example: pragma solidity ^0.4.8; contract A { B public b; function foo() { b = new B()...
eth's user avatar
  • 85.5k
4 votes

Constructor Arguments for verification on Etherscan.io

The parameters for the constructor are appended to the contract. If you look at the "Input Data" in the contract creation transaction https://etherscan.io/tx/...
Ismael's user avatar
  • 30.5k
4 votes
Accepted

Can a function with the same name as the contract be declared both as a function and a constructor?

In Solidity version 0.4.24 declaring a function with the contracts name as as constructor has been depreciated in favor for constructor() If you are using an older version of Solidity than 0.4.24, ...
Connor's user avatar
  • 196
4 votes
Accepted

Remix: 0x0 Transaction mined but execution failed due to construction

Update: I am able to deploy my contract using solidity ^0.5.0 but higher versions does not work. Is your private network using the Constantinople EVM? If you can deploy 0.5.0 but not 0.5.7, you might ...
iamdefinitelyahuman's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible