Questions tagged [constructor]

The tag has no usage guidance.

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

Reflect.finance token-type deployment: change distribution on constructor

I am developing a token based on reflect.finance / safemoon way of work with reflections between holders, but I always reach an error when trying to distribute the initial token supply between ...
0
votes
2answers
24 views

Value assignment for storage variable (in declaration VS in constructor)

What difference does it make if I assign the value of a storage variable in the same line where it is declared vs if I assign its value in the constructor? Which would be the preferred approach? And ...
0
votes
1answer
24 views

How to use constructor to set interfaces addresses?

No really a problem, just need to understand a few things : With this piece of code, transaction is reverted when calling "getEstimatedTokenForBNB" function. // Initialize Parameters ...
0
votes
2answers
47 views

What does an explicit conversion from an address to a contract type actually do in Solidity?

I'm starting in solidity development and I saw this being used in a contract and I didn't quite understand the meaning of it. contract A { address bAddress; constructor(address b){ ...
0
votes
1answer
32 views

Initialize state variables vs constructor [duplicate]

What is the purpose of Constructor if I can initialize the state variables directly. contract ConZ { address public owner = msg.sender; uint public x = 123; } _ contract Conx { address ...
0
votes
0answers
12 views

TypeError : Member "userAddress" not found or not visible after argument-dependent lookup

Im trying to use constructor to assign user address to msg.sender constructor() { userAccount.userAddress = msg.sender; } userAddress being a property in my struct datatype , but i keep getting this ...
0
votes
1answer
17 views

I deployed a contract on remix, but none of the constructor variables are viewable

I inherited the ERC-20 standard contract, but when I compile and deploy, none of the constructor variables are viewable. This problem persists even when I change "private" to "public&...
0
votes
1answer
36 views

Correct Constructor arguments for basic timelock contract

just wondering why I can't get this constructor to pass. What am i doing wrong ? // SPDX-License-Identifier: MIT // TeamLockTest pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/...
1
vote
1answer
33 views

Cloning while providing arguments for construction function

I am trying to clone my contract by using Clones.sol from OpenZeppelin. The cloning procedure is successful, although I cannot pass them my desired arguments which should be provided for construction ...
0
votes
1answer
12 views

I'm trying to deploy a Wallet onto the Blockchain AND deposit some Ether in it AT THE SAME time...... ie using the Remix DEPLOY button

I feel this should be VERY SIMPLE. So code the Constructor to require an Amount and therefore that Amount will be then taken from the Metamask Wallet at the same time as the GasFees are paid for the ...
0
votes
0answers
18 views

How to turn constructor arguments into ABI-ENCODED values?

The constructor of my smart contract has arguments. How can I turn constructor arguments into ABI-ENCODED values? I have to use it on bscscan.com.
0
votes
0answers
6 views

parsing error in smartcontract constructor

parsing error in smartcontract constructor, can some one please help me out and show me what I am doing wring and why this error is even thought everytrhing is looking fine from outside.
2
votes
0answers
255 views

Error! Invalid constructor arguments provided. Please verify that they are in ABI-encoded format, I tried (https://abi.hashex.org/) but still no luck

Good afternoon! I want to create a NFT and my code is working fine in remix. An error occurred while adding source code to ropsten: Error! Invalid constructor arguments provided. Please verify that ...
0
votes
0answers
30 views

Buying ERC1155 token with payable

The constructor for ERC1155 token standard looks like this: constructor() public ERC1155("https://game.example/api/item/{id}.json") {} However, the example given on OpenZeppellin mints all ...
0
votes
1answer
71 views

constructor doesn't trigger on deployment

I have a problem that I don't understand. I wrote a token contract that will be used as a reward for a yield farming contract. The thing is that the constructor doesn't trigger when I deploy it with ...
0
votes
0answers
35 views

How to view what arguments were passed to the constructor function of a deployed contract retroactively

Take this Animetas NFT contract for example: https://etherscan.io/address/0x18df6c571f6fe9283b87f910e41dc5c8b77b7da5#code I want to see what values were passed into the constructor function when this ...
0
votes
1answer
21 views

Question about constructors taking an argument

This is my first experience with programming on Ethereum. I'm deploying the sample contract following the instructions shown here. // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.7.6; ...
0
votes
1answer
397 views

Ethers js deploy contract with balance, payable constructor

I have a smart contract with a payable constructor. I'm trying to figure out the syntax with ethers js how I can deploy the smart contract and send an initial balance with the deployment. const ...
1
vote
1answer
772 views

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

This is so frustrating and I don't know why these errors don't give more information. I compiled and deployed a contract in remix using the left panel and everything is working fine. I then proceeded ...
0
votes
1answer
19 views

Does it matter if state variables are assigned value in line or in the constructor?

For example, is there a difference between these two snippets of code, or is there a best practice? From my experimentation, it doesn't seem like it makes a difference. Thanks. contract A { uint ...
0
votes
1answer
34 views

The called function should be payable if you send value and the value you send should be less than your balance

This is one of my parent contract (child factory contract) functions that creates a child contract. The function should be provided with 3 arguments function breed(uint _number, uint _amount, ...
0
votes
1answer
39 views

Converting constructor from 0.4.25 to latest version

The syntax of constructor in version 0.4.25 was contract A { address newContract; function createContract(uint a, string memory b, address c) public { newContract = new B(a, b, c); } } ...
1
vote
1answer
449 views

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

Hello I keep getting this error and I can't seem to fix it, I'm new to all this, but I'm trying to get better. So someone said if you changed the solidity to the newest version it would fix the ...
0
votes
1answer
224 views

Sending ERC20 token to the constructor of a contract

I want to send an erc20 token to the constructor of a contract. I can't manually use the approve(spender, amount) function before deploying the contract as the spender address needs to be the address ...
0
votes
1answer
23 views

When can you use this in a constructor?

I am going through the solidity docs and I have seen that: // Functions can // be accessed directly or through `this.f`, // but the latter provides an external view // to the function. ...
1
vote
0answers
65 views

Creating Initial ERC721 Tokens Programmatically

I'm interested in minting 100 unique tokens in the constructor of a smart contract, but I'm having an issue where the minting function hasn't been defined yet while the constructor runs. Do I have to ...
3
votes
1answer
195 views

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

Possible outputs of the Solidity compiler include creation bytecode and deployed (runtime) bytecode. However, this compiled deployed bytecode might not be the same as the one that will actually be ...
0
votes
1answer
88 views

Deposit Money Automatically On Child Creation In Factory Pattern

I am implementing a factory pattern contract and on my constructor I want to deposit money into my child contract as soon as the child is rendered --Factory-- function newChild() { Child child = ...
0
votes
1answer
51 views

Push large number of items in mapping with constructor or other methods

I would like to push large number of items into mapping. Prototype looks like this mapping (uint => string) ipfs_hashes; constructor() ERC721("GameItem", "ITM") public { ...
0
votes
1answer
614 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
486 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
504 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
24 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
47 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
33 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 ...
2
votes
2answers
324 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
131 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 ...
1
vote
0answers
341 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
692 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
580 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
77 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; }
2
votes
1answer
4k 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
31 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
102 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); } ...
4
votes
3answers
2k 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
138 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
104 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
68 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
395 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
597 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 ...