Questions tagged [constructor]
The constructor tag has no usage guidance.
162
questions
1
vote
0
answers
18
views
How to pass argument with a specific interface into constructor for a sucessfull etherscan verification?
I have an marketplace contract that needs to be verified. It looks like this:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol&...
1
vote
2
answers
37
views
Store string as immutable
I want to deploy an nft contract and i want to enter URI in constructor:
string immutable i_uri;
constructor(string memory name, string memory symbol, string memory uri) ERC721(name,symbol) {
...
0
votes
1
answer
25
views
passing bytes32 to constructor
i have consutructor who takes a bytes32 parametres and assing its value to the jobID variable
contract APIConsumer {
bytes32 public jobId;
constructor( bytes32 _jobId) {
jobId = _jobId;
}
But ...
0
votes
1
answer
30
views
Facing constructor arguments error while running my staging tests on the goerli network
here is my staging test below which I am trying to test on goerli network:
const { assert, expect } = require("chai")
const { getNamedAccounts, ethers, network } = require("hardhat"...
0
votes
1
answer
62
views
How to encode a call to deploy a proxy inside a smart contract?
In hardhat, I am deploying an upgradeable smart contract using this script:
const v1contract = await upgrades.deployProxy(
V1contract,
[
"...
0
votes
1
answer
35
views
contract recursive dependency
i have two contracts the first one has a function which must be called only by the second contract :
contract A {
address contractBAddress;
uint256 number;
modifier onlyB() {
...
1
vote
1
answer
97
views
How to match number of arguments in constructor and deploy()
This is my constructor
constructor (uint256 _initialSupply) {
ownerOfContract = msg.sender;
balanceOf[msg.sender] = _initialSupply;
totalSupply = _initialSupply;
}
But ...
0
votes
1
answer
23
views
Is it possible to call a function at the time of deployment if it is not in constructor?
This code is from UniswapV2Pair.sol
constructor() public {
factory = msg.sender;
}
// called once by the factory at time of deployment
function initialize(address _token0, address ...
0
votes
0
answers
65
views
Deploy upgradable contracts using Remix
How can I deploy a contract that has the initialize method from Remix? I have just seen here that Remix now supports this feature but I haven't found any example I could follow.
0
votes
1
answer
140
views
How to initialize a smart contract using Remix?
I have a contract that has this constructor:
constructor(address _nativeTokenWrapper) TokenStore(_nativeTokenWrapper) initializer {}
And this initialize function:
/// @dev Initiliazes the ...
0
votes
1
answer
19
views
How constructor can receive a variable quantity of parameters?
I'm coding a contract factory that will generates a lot of contracts and each contract will receive the constructor below:
constructor(
string memory _name,
string memory _symbol,
string ...
1
vote
2
answers
54
views
How to create migration for smart contract with Struct Array in constructor
I have a smart contract that has the following Struct Array in its constructor:
struct Details {
string tokenType;
address tokenAddress;
uint256 tokenId;
uint256 amount;...
0
votes
2
answers
65
views
TypeError: Contract should be marked as abstract
I'm getting this error:
TypeError: Contract "BaseRegistrarImplementation" should be marked as abstract.
--> Contracts/BaseRegistrarImplementation.sol:7:1:
|
7 | contract ...
0
votes
1
answer
19
views
Implementing multiple Can't Be Evil license in one contract
I'm looking for a way to implement Can'tBeEvil License in my project, so that the users can select a particular license whatever they prefer. Can it be done in one contract? or i have to create ...
0
votes
1
answer
140
views
Can ReentrancyGuard be used in Proxies?
ReentrancyGuard's _status is set in the constructor & we can't set it anywhere else: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/64e48203cecad94f02de9891ecdeed4d629c6dae/contracts/...
0
votes
1
answer
45
views
Truffle: { Error: Invalid number of parameters for "undefined". Got 0 expected 1! at module.exports
I am trying to execute the following smart contract using Truffle:
pragma solidity 0.5.16;
contract Phishable {
address public owner;
constructor (address _owner) public{
owner = ...
0
votes
1
answer
24
views
Why do we need constructor in this code?
I heard that constructor is usually used for initializing variables but It just has 'console.log' here. Is constructor essential for every contract?
// SPDX-License-Identifier: UNLICENSED
pragma ...
0
votes
1
answer
23
views
Connect Recipient Wallet - 'receive' function not defined
sorry to bother, trying to get an acknowledgment that my sender(msg.sender) address is sending to the receive() external payable. compiles fine, doesn't deploy correctly to show +1ETH in recipient ...
0
votes
0
answers
179
views
passing multiple parameters to deploy script (ethers, upgrades)
I'm looking for the tutorial or instruction manual for parameter syntax
My solidity file has the following initializer:
function initialize(
address addy,
string memory _var1,
string ...
1
vote
1
answer
61
views
Restrict who can call a constructor
I create an instance of a child contract using a Factory contract. I want to limit the constructor of the child to only be called by the Factory. Is this possible?
contract Factory {
function ...
1
vote
1
answer
91
views
Why is VRFConsumerBaseV2(vrfCoordinator) in the constructor declaration?
I am new to Solidity and going through Patrick Collins' online course. In the following code, I was wondering why VRFConsumerBaseV2(vrfCoordinator) is included in the constructor declaration. I ...
2
votes
1
answer
60
views
Vyper: Call function in __init__, Function does not exist or has not been declared yet
I have some vyper code as such:
# SPDX-License-Identifier: MIT
# @version ^0.3.3
supply: uint256
decimals: uint256
@internal
def updateSupply(_supply: uint256):
self.supply = _supply
@external
...
0
votes
2
answers
199
views
How do you pass in a variable as a string to a constructor in solidity
I'm currently working on an NFT project, using the openzeppelin ERC721 standard for the nfts.
When Inheriting the ERC721 NFT contract standard from openzeppelin you're required to pass in the "...
0
votes
1
answer
123
views
Solidity dynamic unicode variable
I previously asked about unicode in Solidity and got some great answers (thanks for that!).
Issue is now I'm experimenting with passing in the value of a utf-8 (not a literal):
constructor (string ...
0
votes
0
answers
24
views
How to set variable of contract from another contract constructor? Solidity [duplicate]
I have a contract
// SPDX-License-Identifier: MIT
pragma solidity ^ 0.8.15;
contract MomContract {
bool public failed =false;
constructor(){
new Son(address(this));
}
...
0
votes
2
answers
73
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
75
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
446
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
443
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
994
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
16
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
54
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
340
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
216
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
3
answers
308
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 ...
2
votes
1
answer
454
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
150
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 ...
1
vote
1
answer
162
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
63
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
380
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
119
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 ...
1
vote
0
answers
327
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
31
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
58
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 ...
4
votes
0
answers
337
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
2
answers
330
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
292
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
...
2
votes
2
answers
778
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
323
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
1
answer
69
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&...