Hi there,
I am trying to read state variables (using hardhat scripts) from a contract deployed on the Rinkeby network. I use the script below but it returns âundefinedâ as if it canât read from the contract.
const hre = require("hardhat");
const { expect } = require("chai");
async function main() {
const [deployer] = await ethers.getSigners();
console.log("Deployed contracts with the account:", deployer.address);
console.log("Account balance:", (await deployer.getBalance()).toString());
const abi = [ { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } ], "name": "OwnershipTransferred", "type": "event" }, { "inputs": [], "name": "owner", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "newOwner", "type": "address" } ], "name": "transferOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" } ];
let provider = ethers.getDefaultProvider('rinkeby');
const designManager = await new ethers.Contract(0x3EB0A404f33eCacfd4e57c8De791e03588eE065C, abi, provider);
console.log("DesignManager address:", designManager.address);
console.log("DesignManager project Name:", await designManager.projectName());
console.log("DesignManager project ID", await designManager.projectID());
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
When I run the script using npx hardhat run scripts/logs.js --network rinkeby
I am getting the terminal output:
Deployed contracts with the account: 0x17*******
Account balance: 1959160072709728500
DesignManager address: 5.528590342605352e+47
DesignManager project Name: undefined
DesignManager project ID undefined
Could you please advise what is wrong in my script and why canât I read the DesignManager and project ID variables from the contract ?