Questions tagged [constructor]
The constructor tag has no usage guidance.
142
questions
0
votes
1
answer
12
views
How to use truffle-assertions to check if a constructor will revert?
Say I have a contract:
contract Reverts{
constructor(param1){
require(param1);
}
}
If param1 is false, the constructor should fail and revert state.
truffle-assertions allows me to ...
1
vote
2
answers
18
views
Smart contract is not available on the blockchain during the constructor call
I have the following sample code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/ERC20....
0
votes
1
answer
34
views
Any way to call the constructor of an inherited contract the initialize function using a proxy?
I am deploying a proxy on an ERC721 and Ownable contract. The problem is that the constructor of Ownable is not called on the initialize function so the owner is not defined and the onlyOwner modifier ...
0
votes
3
answers
27
views
can we call constructor in another function of the same contract in solidity?
can we call constructor in another function of the same contract in solidity ? Curious, Kindly reply asap. Thanks
0
votes
1
answer
142
views
Passing an array of constructor arguments through hardhat-etherscan in CLI
Here is the code that I used to deploy this contract to the Rinkeby network.
const hre = require("hardhat");
async function main() {
// Hardhat always runs the compile task when running ...
0
votes
0
answers
13
views
Hello there i've problem with Expected primary expression
hello this is my code and error
constructor(address _supplyChainAddress) public {
supplyChainStorage = SupplyChainStorage(_supplyChainAddress);
}
and this is an error and i got stuck because ...
0
votes
1
answer
27
views
Weird problem with address(this).balance and gas
I have a very simple contract, something like this:
contract Test_Variable{
uint256 public variable;
constructor() {
variable = 100;
}
function balanceTest() public {
...
0
votes
0
answers
95
views
Hardhat Error: " reason: 'missing argument: passed to contract'," error
I am creating a basic NFT website. I have two smart contracts, one to mint the NFT and one to whitelist.
My main contract inherits the whitelist contract. When I try to deploy the contract I keep ...
0
votes
1
answer
88
views
Uncaught TypeError: web3 is not a constructor. the blockchain website cannot connect to metamask
i have issue on web3 = new web3 (web3.currentProvider);
below is the code. it said web3 is not a constructor. is it like the capital letter issues?
the version of my web3 is "^1.3".
var ...
0
votes
1
answer
54
views
Contract deployment with the user interface
My smart contract constructor function accepts 2 parameters for being deployed.
I have developed a user interface for this contract by Hardhat, React, and Ethers.
Now I want to create an HTML form on ...
1
vote
0
answers
99
views
The reason why can't I use calldata as a data location for constructor parameter
I know what is difference between memory and calldata.
But seeing that I ask this question I don't seem to understand deeply yet.
I ran into an error message as below, when I used 'calldata' as a data ...
0
votes
0
answers
44
views
How do I concatenate using Console.log in remix?
This is a pretty basic thing I'm trying to do; What I'm trying is to print a string of data using a for loop in the constructor, but the data won't concatenate.
Can someone suggest?
Smart contract ...
0
votes
1
answer
37
views
Why can immutable state variable not be initialised inside an if else statement?
I would like to initialise an immutable state variable inside an if else statement as follows:
contract Simple {
bool immutable isNatural;
constructor(uint number) {
if (number != 0) {
...
0
votes
1
answer
34
views
I am not being able to understand the constructor function of the given smart contracts
In the smart contract code below, there is a function being executed inside the constructor function. Can anyone please explain what is happening in the constructor?
pragma solidity 0.8.7;
import &...
1
vote
1
answer
76
views
Is there a way to override or skip calling a parent's constructor?
Is there a way to override or skip calling a parent's constructor? For example, I have the following:
contract Ape {
constructor() {
// Initialise some stuff in Ape constructor
}
}
contract ...
0
votes
0
answers
52
views
Transaction mined but execution failed
I was trying to deploy my smart contract to BSC testnet using Remix IDE,although it compiles successfully but when I try to deploy it I get this error message.
"false Transaction mined but the ...
0
votes
0
answers
100
views
How to parse constructor arguments on contract creation transaction using ethers.js?
Ethers.js has a parseTransaction function that can be used in the following way to extract arguments from any transaction on a deployed contract.
const txDescription = contractInfo.interface....
1
vote
0
answers
17
views
does solidity compiler convert to immutable implicitly?
I was wondering if the solidity compiler automatically sets a state variable to immutable if it is never modified?
example
contract MyContract {
uint256 myNumber;
constructor(uint256 _myNumber){
...
0
votes
1
answer
22
views
Why no private constructors in solidity?
I am looking for a mechanism that allows me to restrict the creation of a contract A from anywhere but another contract B.
contract A {
// ...
}
contract B {
constructor() {
A a = new ...
2
votes
0
answers
181
views
Decode parameters on contract creation or constructor parameters
I want to decode parameters passed to contract constructor. Even if i used the ABI of the contract, it doesn't seem to resolve the parameters used.
Here is the transaction trace out put
https://gist....
0
votes
0
answers
15
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
2
answers
117
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
1
answer
75
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
2
answers
295
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
1
answer
132
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
0
answers
23
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
1
answer
26
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
1
answer
149
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
1
answer
70
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
1
answer
15
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
0
answers
67
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
0
answers
9
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
0
answers
451
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
0
answers
56
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
1
answer
128
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
0
answers
76
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
1
answer
22
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;
...
1
vote
1
answer
1k
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 ...
2
votes
1
answer
2k
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
1
answer
48
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
1
answer
48
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
1
answer
95
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
1
answer
1k
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
1
answer
349
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
1
answer
27
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
0
answers
73
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
1
answer
488
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
1
answer
143
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
1
answer
115
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
1
answer
1k
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 ...