Questions tagged [constructor]
The constructor tag has no usage guidance.
93
questions
0
votes
1answer
23 views
Pass mapping as constructor parameter
I'd like to save the contract addresses from DAI and UNI into a mapping when calling the smart contract constructor depending on the network. Below is a minimalistic example that works fine:
contract ...
1
vote
1answer
58 views
Using inherited constructor in Solidity >=0.5.0
I want to use a contract inherit from another contract and use the parent constructor after using another commands in inherited constructor. So I wrote:
pragma solidity ^0.5.10;
contract A {
...
0
votes
1answer
47 views
Cannot figure out how to set constructors and ABI for a contract
So I've been breaking my head over this for the last 2 days. I cannot seem to figure out how to get the constructors and ABI set up properly.
I'm testing smart contracts by copying Sushi contract from ...
1
vote
0answers
14 views
How to enable constructors in the new REMIX IDE or Truffle framework since MIST is depreciated
I used to dabble with making tokens and contracts and started to get back into it.
I liked the functionality that mist offered where you could input constructors values directly in mist. I can not ...
0
votes
1answer
28 views
Truffle cant deploy contract with reverting constructor
I'm developing a dapp with the truffle suite and now I'm running into a problem.
Everything is working locally in the ganache instance.
My contract should disallow direct payments to the contract, so ...
0
votes
1answer
18 views
How much Ether does a Smart Contract Address hold before a Payable Instantiation?
The following code always reverts to "Contract must be empty".
But shouldn't address(this).balance == 0 if the contract hasn't even been instantiated yet?
Maybe since the contract doesn't ...
0
votes
1answer
44 views
Can someone read this private variable?
my purpose is to generate a random key when the smart contract is created and save that key in a private variable. I don't what to know its value either.
Let's take for example the code below:
pragma ...
1
vote
1answer
45 views
What happens when a Contract is added to the genesis block?
Recently I found out that you can add smart-contracts to the genesis block (genesis.json) of your local ethereum network.
Since normally, when you add a smart-contract via a transaction, you can call ...
0
votes
0answers
48 views
How to listen for contract creation, or all block events?
I'm building a web app with web3 where users can deploy a certain contract and assign some people to it. Inside the constructor of that contract I also output a certain event. I want these assigned ...
3
votes
0answers
81 views
Passing constructor arguments from child contract to parent contract
The ERC721 standard contract requires a token name and symbol in its constructor. I have inheritance pattern that looks likes Contract A is B and Contract B is ERC721.
If I want to set my token name ...
2
votes
1answer
146 views
How do I set the constructor arguments when deploying using OpenZeppelin CLI?
My Token contract compiles fine using solidity 0.5.0:
import "/Users/lennard/Desktop/GGToken/node_modules/@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
import "/Users/lennard/Desktop/...
2
votes
1answer
26 views
can a hacker call constructor() function after deploy if it is public? [duplicate]
Is below function can be called by a hacker after deploy
constructor() public
{
test = true;
}
3
votes
1answer
1k views
Error: This contract may be abstract
My solidity contract compiles in Remix, but when I try to deploy it it fails and throws
Error: This contract may be abstract, not implement an abstract parent's methods completely or not invoke an ...
0
votes
1answer
25 views
Trouble deploying one contract from another
Why creating a contract new RewardCourts() in another contract takes more than ten kilobytes of bytecode in the contract it is called from? (It makes bytecode too big and I can't deploy it!)
What to ...
1
vote
1answer
39 views
Payable constructor gives revert message
I am trying to execute the following contract on remixe IDE:
pragma solidity ^0.5.4;
contract GuessTheNumberChallenge {
constructor() public payable {
require(msg.value == 1 ether);
}
...
2
votes
3answers
391 views
Passing constructor arguments to the CREATE assembly instruction in solidity
I have a contract which deploys other contracts by bytecode:
contract DeployContract {
function deploy(bytes calldata _bytecode) external returns(address addr) {
bytes memory bytecode = ...
1
vote
1answer
91 views
How to share TypeScript code between truffle tests?
I have some code in my TypeScript tests, say:
function foo() {
return 'bar';
}
which I'd like to share with all my tests. The simple solution is to copy the function into each *_test.ts file.
...
1
vote
1answer
30 views
Error: invalid address in solidity constructor
I get a huge error message (~1MB) starting with
Error: invalid address (arg="_readAccess", coderType="address", value={"constructor":{"contractName":"SenderAccess","abi":[...
when executing a test ...
0
votes
1answer
61 views
Stack too deep problem
I try to add more property to the scenario struct but when I run the compile the same error appear:
struct Scenario {
uint id;
address payable author;
address editor;
...
1
vote
1answer
126 views
Can you emit events in a contract constructor?
I have a constructor that is emitting an event, but cannot seem to see/catch/filter that event after deployment.
1
vote
2answers
266 views
Remix: 0x0 Transaction mined but execution failed due to construction
I have the following example smart contract, where I cannot deploy using remix into my private network using environment Web3 provider. The error I am getting is Transaction mined but execution failed ...
0
votes
1answer
369 views
Uncaught TypeError: web3.eth.Contract is not a constructor
For whatever reason, when I attempt to set an instance of a contract in a javascript file, I get the following message in my console:
Uncaught TypeError: web3.eth.Contract is not a constructor
At ...
0
votes
1answer
158 views
Storing geo location in contract
I am beginner in solidity programming, I am trying to write my first contract. I am trying to store a piece of land (which is array of coordinates) against a person. I am having trouble storing the ...
0
votes
1answer
168 views
passing variables between different contract by solidity (0.5.0+ version)
I writed ERC20 contract and ICO contract for a test , but I meet a lot problem with compile problem.
My ERC20 contract have own constructor
but,I also need a ICO contract(a control)for passing ...
0
votes
0answers
18 views
Unexpected behaviour. Huge size increase when adding new SubContract()
I have a contract similar to:
contract Contract01 {
SubContract _refContract;
...
constructor() public {
refContract = new SubContract();
}
function setSubContractRef(SubContract ...
1
vote
1answer
284 views
How to pass arguments to token smart contract generator?
I'm trying to build a 'token generator' smart contract that accepts 3 arguments to then deploy a new token smart contract with those inputs ('strings' for symbol, name, 'address' for owner). I am a ...
0
votes
1answer
15 views
Function inside constructor is called from which address?
interface token {
function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);}
contract CampaignFactory{ token public token_instance;
constructor()...
1
vote
1answer
235 views
Solidity : Error when pushing an address into a dynamic address type array
I'm trying to insert an address into an address type dynamic array. It works well when I do the operation inside a function. There are no errors and the elements are properly pushed into the array.
...
2
votes
3answers
224 views
Is a constructor needed to set a contract owner?
until now I have set the owner in a contract like so:
pragma solidity ^0.5.2;
contract SampleContract{
address payable owner = msg.sender;
}
in the docs it is suggested to do it this way:
...
1
vote
2answers
1k views
Contract deployment using web3.eth.contract(abi) with constructor arguments
I'm trying to deploy the following smart contract:
pragma solidity ^0.5.00;
contract TestContract {
address public owner;
string public word;
constructor(string memory _word) public{
...
1
vote
2answers
400 views
Encode constructor arguments used when deploying a contract
How can I encode the constructor arguments when deploying a contract?
Here is my deployment function:
async function deploy(abi, bin, args) {
let contract = new this.web3.eth.Contract(JSON.parse(...
1
vote
1answer
229 views
What does etherscan mean by “Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)”?
I'm inspecting a contract on etherscan, at the following URL:
https://etherscan.io/address/0x5cb5f46a655c02889172323760d12d0e5d83cdaf#code
At the bottom of the web-page, I see two sections:
...
1
vote
1answer
242 views
How can I retrieve the constructor arguments used during contract deployment
I know how to extract the constructor arguments out of the transaction object returned from a contract-deployment operation.
It is explain in web3.js official documentation here.
But this is not an ...
0
votes
1answer
209 views
Making a contract with new keyword address is always 0x0000000000000000000000000000000000000000
I'm making a contract that makes other contracts. Once the contract is made using address tokenAddress = new MyToken('Name'); I want to save the address of the contract, tokenAddress, in MyStruct. ...
2
votes
1answer
260 views
Solidity Constructor Parameter List
Which variables types are accepted by a constructor in Solidity? In particular, is it possible to pass an actual contract as an constructor input? For example:
contract ContractA {
constructor (...
0
votes
1answer
43 views
Constructor Function: How can I tell which function is the constructor?
How can I tell which function is the constructor function?
In the OpenZeppelin implementation of the MultisigWallet, OpenZeppelin claims this is the constructor function:
/**
* Constructor, sets ...
1
vote
1answer
59 views
Solidity Syntax question
What happens if a function is being passed before { into another function?
Like DetailedERC20(_name, _symbol, TOKEN_DECIMALS) in this example:
function MyToken(Registry _registry, string _name, ...
2
votes
1answer
152 views
Getting and storing address of erc20 contract after dynamically creating it
I have a function which dynamically creates an ERC20 contract on calling a function in another contract as follows:
function createDao(string _tokenName) public payable {
tokenNumberIndex = ...
2
votes
1answer
342 views
How does a contract's constructor work and load input values?
I set up the following contract:
pragma solidity ^0.4.25;
contract Simplest {
uint x;
constructor(bool _lucky) public {
if (_lucky == true) {
x = 7;
} else {
...
1
vote
1answer
106 views
problem with constructor parameter in rawtransaction
I am using remix and ganache to test out my contract. The contract deploys successfully, however, I do not see the state variables initialized with the constructor parameters when I look at the ...
1
vote
0answers
110 views
the constructor should be payable if you send
I have been testing the code and for some reason I am having a block. The error is described as "the constructor should be payable if you send value". The debugger points to " uint256 weiAmount = ...
0
votes
1answer
70 views
Smart Contract Testing
I am writing test driven smart contracts. There is one smart contract with parameterized constructor. And I am using the require statement in the constructor. I want to catch the error in my test ...
0
votes
1answer
69 views
When extending a contract how to call the external constructor and pass parameters?
I have the following contract
import "zeppelin-solidity/contracts/token/ERC721/ERC721Token.sol";
contract Contract is ERC721Token {
function Contract(string _name, string _symbol) public {
...
4
votes
1answer
189 views
Purpose of the function with the contract's name?
What is the purpose of the WithdrawalContract function in this case? If becomeRichest doing exactly same but with a certain condition and adding a pending withdrawal to the pendingWithdrawals.
0
votes
1answer
453 views
Deploying a contract with a “payable” constructor and including input parameters?
There is a useful Solidity contract HERE. However, there are two things at time of its deployment:
(1) The first thing is the contract balance since its constructor is payable.
(2) And the second ...
0
votes
1answer
232 views
Solidity state variable resets to default inside function
For this project, I am coding smart contracts for Ethereum using Solidity.
In the following code, the variable numCertificates should initially be 1. Nonetheless, newCertificateId is 0 when assigned. ...
2
votes
1answer
262 views
Initializing fixed-size storage array given function parameter
I would like to store an array of fixed size in my contract storage, with a user-defined size, initialized to all 0s. Here's an example contract:
pragma solidity ^0.4.24;
contract Test {
...
0
votes
1answer
41 views
Advantage of using a contract contructor with parameters
What is the advantage of using a constructor with parameters instead of hard coding the values? Is there a possibility to reuse a once deployed contract?
0
votes
1answer
403 views
Fixing warning about “constructors” causes new error referencing the old function name [duplicate]
I'm using the solidity code for deploying new ERC20 tokens found here and quoted below:
pragma solidity ^0.4.16;
contract owned {
address public owner;
function owned() public {
...
3
votes
1answer
122 views
v0.4.22 solc compile failing - not predictable behavior
Error:
Warning: Defining constructors as functions with the same name as the contract is deprecated. Use "constructor(...) { ... }" instead.
function CappedCrowdsale(uint256 _cap) public {
^ (...