Questions tagged [constructor]
The constructor tag has no usage guidance.
179
questions
0
votes
0
answers
13
views
How to Extract Constructor Params from Deployed Bytescode
Constructor Params are written to the end of the contract bytecode. However, it's hard to identify where Constructor Params start and end just by looking at the low-level bytecode.
Of course, there is ...
0
votes
0
answers
11
views
How to read encoded Constructor Arguments
some contract has the following constructor:
constructor (address _walletsForCharity, uint160[] memory _pair)
Now I want to check which _walletsForCharity were getting used.
When I am on the contract ...
1
vote
1
answer
26
views
passing constructor arguments to 0-arg constructor at contract create
Suppose the contract (written in Solidity) has only one constructor, and that a 0-arg constructor. Suppose now in a contract create transaction you supply constructor arguments.
Is that an error that ...
0
votes
0
answers
33
views
How do I determine the constructor bytecode for contracts created by another contract
I am looking to decode constructor arguments for EVM contracts. Some contracts are created by externally owned accounts, but many are created via a contract transaction.
In both cases how can I ...
0
votes
0
answers
38
views
How to solve constructor params missing issue?
This is my constructor code for the trading receiver
constructor(address _staking, address _trading, address _lzEndpoint)
NonblockingLzApp(_lzEndpoint)
{
liquidityI = ...
1
vote
2
answers
31
views
Assigning the owner variable outside of constructor or function
How is assigning a variable outside of a constructor or a function legit?
contract A {
address public immutable OWNER = msg.sender;
}
1
vote
1
answer
57
views
Meaning of msg.sender in constructor
What is the meaning of a msg.sender in a constructor? Is it strictly the owner of a contract or any EOA account calling the contract?
1
vote
2
answers
92
views
Verification of a proxy contract not working because of constructor args
I am creating a smart contract verification service as a learning experiment and I am now able to verify most of contracts that I come across etherScan (in part doing so there is not only an option).
...
2
votes
1
answer
380
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
32
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
52
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
116
views
Solidity Proxy: why using initialiser instead of a constructor?
Why proxies can't read from the constructor?
0
votes
1
answer
15
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
41
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
1
answer
69
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/...
1
vote
1
answer
44
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
190
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
2
answers
134
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
25
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
47
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
41
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
357
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
135
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
113
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
263
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
82
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
358
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
73
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
2
answers
318
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
2
answers
504
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
32
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
137
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
274
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
33
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
2
answers
1k
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
77
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
26
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
385
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
105
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
161
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
137
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
524
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
195
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
188
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
176
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....
2
votes
1
answer
830
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
895
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
2k
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 ...