Hey all! I have a smart contract that I need to deploy that accepts another smart contract as parameter of its constructor. I'm testing this using Chai just to see how this is done. But I get a an "invalid address ENS name" error message.
Feb 22, 2022, 6:15 AM
what contract address parameter are you putting in the call to the constructor?
is it perhaps not formatted as a proper ETH address?
Feb 22, 2022, 6:17 AM
The smart contract that requires another smart contract as parameter is coming from the contractFactory. It's not asking for an address.
Feb 22, 2022, 6:18 AM
ok, but what address is getting used?
Feb 22, 2022, 6:19 AM
In the contract itself, say ContractA, and ContractB where ContractB is passed to ContractA in its constructor
Feb 22, 2022, 6:19 AM
ok...can you post the code or screenshot of the code that has the call to the ContractA constructor?
Feb 22, 2022, 6:20 AM
Below is the snippet
contract Farming {
string public name = "Farm";
uint public apy;
address public owner;
PondToken public pondToken;
// address public rewardAddress;
address[] public stakers;
mapping(address => uint) public stakingBalance;
mapping(address => uint) public stakingTime;
mapping(address => bool) public hasStaked;
constructor(PondToken _pondToken) {
pondToken = _pondToken;
owner = msg.sender;
// rewardAddress = msg.sender;
apy=10000;
}
string public name = "Farm";
uint public apy;
address public owner;
PondToken public pondToken;
// address public rewardAddress;
address[] public stakers;
mapping(address => uint) public stakingBalance;
mapping(address => uint) public stakingTime;
mapping(address => bool) public hasStaked;
constructor(PondToken _pondToken) {
pondToken = _pondToken;
owner = msg.sender;
// rewardAddress = msg.sender;
apy=10000;
}
Feb 22, 2022, 6:21 AM
ok, and the call to that constructor?
can you post that?
Feb 22, 2022, 6:22 AM
This is PondToke in the same sol file: contract PondToken {
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
string public constant name = "Pond";
string public constant symbol = "POND";
uint8 public constant decimals = 18;
mapping(address => uint256) balances;
mapping(address => mapping (address => uint256)) allowed;
uint256 totalSupply_;
constructor(uint256 total) {
totalSupply_ = total;
balances[msg.sender] = totalSupply_;
}
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
string public constant name = "Pond";
string public constant symbol = "POND";
uint8 public constant decimals = 18;
mapping(address => uint256) balances;
mapping(address => mapping (address => uint256)) allowed;
uint256 totalSupply_;
constructor(uint256 total) {
totalSupply_ = total;
balances[msg.sender] = totalSupply_;
}
below is the test in Chai: it("Should create PondToken and Farming Contract Instances", async function () {
const Farming = await ethers.getContractFactory("Farming");
const PondToken = await ethers.getContractFactory("PondToken")
const pondTokenInstance = await PondToken.deploy(totalSupply);
const farmingInstance = await Farming.deploy(PondToken);
/*let result = await farmingInstance.getRewardTokens();
console.log(`Result ${result}`)*/
});
const Farming = await ethers.getContractFactory("Farming");
const PondToken = await ethers.getContractFactory("PondToken")
const pondTokenInstance = await PondToken.deploy(totalSupply);
const farmingInstance = await Farming.deploy(PondToken);
/*let result = await farmingInstance.getRewardTokens();
console.log(`Result ${result}`)*/
});
Feb 22, 2022, 6:23 AM
this line is likely wrong:
const farmingInstance = await Farming.deploy(PondToken);
const farmingInstance = await Farming.deploy(PondToken);
You want:
const farmingInstance = await Farming.deploy(pondTokenInstance.address);
const farmingInstance = await Farming.deploy(pondTokenInstance.address);
Feb 22, 2022, 6:24 AM
I passed the pondTokenInstance and I got the same error message
Feb 22, 2022, 6:24 AM
you need .address
Feb 22, 2022, 6:24 AM
I think so too.
The constructor from Farming contract should be accepting an address of the PondToken contract. This contract was given to me to have a look at.
Feb 22, 2022, 6:26 AM
yes, try using pondTokenInstance.address
Feb 22, 2022, 6:26 AM
that worked!
first time doing that. thanks man.
Feb 22, 2022, 6:27 AM
no prob
Feb 22, 2022, 6:30 AM
I am trying to make a
transaction using web3 js
But txhash is undefined
transaction using web3 js
But txhash is undefined
I am using buffer.from for pvt key conversion
Feb 22, 2022, 7:08 AM
hard to say without seeing your code
Feb 22, 2022, 8:09 AM
Can I dm you
Feb 22, 2022, 8:32 AM
sure
Feb 22, 2022, 8:47 AM
anyone here have a good Javascript example of sending transacction from a Chai test script? I have a simple function in an ERC20 contract and in my Chai script is the syntax: contractInstance.stakeTokens(_amount) but I keep getting an error message "transaction reverted for no reason"
or something to that effect.
Feb 22, 2022, 10:26 AM