Open LeeJianXing opened 1 year ago
I think this migth be the problem:
For ethers version 6 you need to use:
console.log(`Contract deployed to ${await contract.getAddress()});
to access the contract's address.
@LeeJianXing aren't you getting a type error when contract.retrieve()?
async function main() {
//http://127.0.0.1:7545
const provider = new ethers.JsonRpcProvider("http://127.0.0.1:7545");
const wallet = new ethers.Wallet(
"0x962355e5534cf73d354b2792432a511f6f70eac52b1d30a085acf9ede3ba5d6a",
provider
);
const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8");
const binary = fs.readFileSync(
"./SimpleStorage_sol_SimpleStorage.bin",
"utf8"
);
const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
console.log("Deploying, please wait...");
const contract = await contractFactory.deploy();
// await contract.waitForDeployment();
console.log(contract);
const transactionReceipt = await contract.deploymentTransaction()?.wait(1);
// console.log(transactionReceipt);
// const nounce = await wallet.getNonce();
// const tx = {
// nonce: nounce,
// gasPrice: 100000000000,
// gasLimit: 1000000,
// to: "0x0000000000000000000000000000000000000000",
// value: 0,
// data: "0x60",
// chainId: 1337,
// };
// const sentTx = await wallet.sendTransaction(tx);
// console.log(sentTx);
const currentFavoriteNumber = await contract.retrieve(); // <========== here
}
I think this migth be the problem:
For ethers version 6 you need to use:
console.log(`Contract deployed to ${await contract.getAddress()});
to access the contract's address.
plus for deployment and waiting for deploying use;
const contract = await contractFactory.deploy();
await contract.waitForDeployment().then(()=>{console.log("success");}).catch(()=>{console.log("unsuccessful");})
await contract.getAddress().then((res)=>{console.log(res);}).catch((err)=>{console.log(err);})
THANK YOU @EggsyOnCode , I'm really giving my best shot to follow the tutorial, this just saved me a ton of time and I'm very grateful, I need to get an Internship Opportunity...
This is my solidity code,i get this error
TypeError: no matching function (argument="key", value="address", code=INVALID_ARGUMENT, version=6.2.3)
tutorial timestamp at : 8:02:50
This is my package.json, the ethers version i followed what is shown in the tutorial