Lesson:5 Unable to access ABI functions. #6645
Unanswered
Hruthik5124
asked this question in
Q&A
Replies: 2 comments
-
You have a syntax error in this line |
Beta Was this translation helpful? Give feedback.
0 replies
-
In v6 this works const contractFactory = new ethers.ContractFactory(abi,binary,wallet);
console.log("Deploying please wait....");
const contract = await contractFactory.deploy();
await contract.deploymentTransaction()?.wait(1);
console.log("Contract address: ", await contract.getAddress());
const FavNumber = await (contract as any)['retrieve']();
console.log('Current FavNumber is: ',FavNumber.toString());
const transactionResponse = await (contract as any)['store']("7");
const transactionReceipt = await transactionResponse?.wait(1);
const updatedFavNumber = await (contract as any)['retrieve']();
console.log('Updated Fav Number is: ', updatedFavNumber.toString()); FULL CODE import { ethers } from "ethers";
import fs, { copySync, watchFile } from "fs-extra";
import 'dotenv/config';
async function main() {
const provider = new ethers.AlchemyProvider('sepolia', process.env.API_KEY!);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY! ,provider);
// const encryptedJson = fs.readFileSync("./.encryptedJsonKey","utf-8")
// let wallet = ethers.Wallet.fromEncryptedJsonSync( encryptedJson , process.env.PRIVATE_KEY_PASSWORD!);
// wallet = await wallet.connect(provider);
// const blockNumber = await provider.getBlockNumber();
// console.log(blockNumber);
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.deploymentTransaction()?.wait(1);
console.log("Contract address: ", await contract.getAddress());
const FavNumber = await (contract as any)['retrieve']();
console.log('Current FavNumber is: ',FavNumber.toString());
const transactionResponse = await (contract as any)['store']("7");
const transactionReceipt = await transactionResponse?.wait(1);
const updatedFavNumber = await (contract as any)['retrieve']();
console.log('Updated Fav Number is: ', updatedFavNumber.toString());
}
main()
.then(() => process.exit(0))
.catch((error)=> {
console.error(error);
process.exit(1);
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm in v6.
In v6
contract.retrieve();
method is not working. Please anyone helpme.Beta Was this translation helpful? Give feedback.
All reactions