Questions tagged [constructor]
The constructor tag has no usage guidance.
176
questions
2
votes
1
answer
338
views
Beacon contract contructor seems to call address 0x02?
The Beacon (Eth 2.0 deposit) contract was once deployed using a certain (constructor) script, like every other contract on the EVM blockchain. While analyzing that constructor script, it seems that it ...
0
votes
0
answers
23
views
creation of PairFlash errored: Error encoding arguments: Error: types/values length mismatch (count={"types":5,"values":11
Getting this error when attempting to deploy a contract that reads in three addresses and two tuples
creation of PairFlash errored: Error encoding arguments: Error: types/values length mismatch (count=...
0
votes
1
answer
16
views
Understanding the Purpose of 'revert' Statement in Constructor of Account Abstraction Repo
I'm using the bundler repo, and during a code review, I'm having trouble understanding why the revert is used in the constructor. The intention seems to be to trigger an error, but using revert in ...
2
votes
2
answers
27
views
Solidity Proxy: why using initialiser instead of a constructor?
Why proxies can't read from the constructor?
0
votes
0
answers
118
views
TypeError: AbiCoder is not a constructor, testing purchaseSnack function is failing. I think due to not handling ether conversion correctly
I am trying to write a test script using hardhat to test the purchaseSnack function but I keep receiving these errors.
1) VendingMachine
Should fail if insufficient funds are sent:
...
0
votes
1
answer
12
views
Question about Ethernaut Telephone question. Creating attack method instead of using constructor
This is entire contract for the ethernaut Telephone question. I created attack() function, but a youtuber suggests constructor(). Anyone knows why?
0
votes
1
answer
33
views
Incorrect use of constructor
I cannot get my code to compile under 0.8.18.
I get the error:
Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is ...
0
votes
0
answers
43
views
Constructor Arguments for verification on Etherscan
I want to verify a contract on Etherscan.io, but I am not able to find the correct Constructor Arguments.
I tried everything which is explained on StackExchange, but cannot get it to verify...
using ...
0
votes
1
answer
37
views
How to find Constructor Arguments for verification on Etherscan.io
I spent 4 days for this work.
plz make me know anybody.
this is solidity code of my token
I use openzeppelin.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/...
0
votes
0
answers
29
views
Inherit constructor of other contract inside an initialize function
I'm trying to inherit the parentContract to the childContract, where the parentContract's constructor requires a parameter to be set, and the childContract is a proxy. Because the childContract is a ...
0
votes
0
answers
20
views
Using inherited constructors with a proxy factory
I am attempting to use Chainlink VRF along with OpenZeppelin's upgradable contracts to generate a random number. In order to use VRF, I must inherit the constructor from VRFV2WrapperConsumerBase. ...
0
votes
1
answer
124
views
Can't create UniswapV2Pair from constructor on Ethereum Mainnet
I want to create a Uniswap Pair in a constructor() block of my token smart-contract.
However, when I try to do this, I get "error":"execution reverted".
Perhaps these nuances will ...
0
votes
0
answers
16
views
array of contracts and contructor with arguments
Strange behavior. I have the following pair of smart contracts:
pragma solidity ^0.8.8;
contract Zone
{
string public a;
string public b;
string public c;
string public d;
constructor(...
0
votes
0
answers
18
views
How to register 'abi-encoded' in bscScan? (noob)
I made a token with '.sol' through 'Remix'.
After that, I copied my token abi, pasted it to 'https://abi.hashex.org/' , and checked the construction function, and it was empty.
What is the '...
0
votes
2
answers
57
views
Constructor Inheritance: : Wrong argument count for constructor call
In the following, why is the constructor of C not inherited by CExt so that it can be used by another extending contract CExtChild?
contract C {
uint id;
constructor(uint _id) {
id = ...
1
vote
0
answers
21
views
Why is adding a constructor to call an external contract causing a cascading effect on the children requiring them to be marked abstract?
I'm having issues with compiling this contract, this contract sits in a series of inherited contracts. Its #6 of 8 contracts that make up the whole NFT contract. Before adding the constructor I was ...
1
vote
2
answers
26
views
Constructor error: Expected '(' but got identifier solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract PokemonFactory {
struct Pokemon {
uint id;
string name;
}
struct Type {
string name;
string description;
}
...
1
vote
0
answers
31
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
158
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
95
views
Passing bytes32 to constructor
I have s constructor that takes a bytes32 parameter and assign its value to the jobID variable
contract APIConsumer {
bytes32 public jobId;
constructor( bytes32 _jobId) {
jobId = ...
0
votes
1
answer
101
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
176
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
62
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
272
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
41
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
1
answer
160
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
360
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
29
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
112
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
172
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
31
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 ...
1
vote
1
answer
493
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
63
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
26
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
332
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
98
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
135
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
106
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
392
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
167
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
148
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
158
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....
1
vote
1
answer
683
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
689
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
1k
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
1
answer
72
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
1
answer
849
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
520
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 ...