Error: With Ethers.js
, no 'writing function' can in an Etherum contract.
When together with intelligent on the Ethereum blockchain, it is the one tools like Ethers.js to an instoctor. However, thee is a crucial step that many developers overlooked in the cration of the one therst Etherum contracts with Ethers.js:
In this articulate we in investigate it rovide of instructions for removal.
The problem:
If you declare a contraction instance in your local hardhat network with
`JavaScript
Const account0 = "0xac0974bec39a17e3ba4a6b4a6b4d238ff944bacb4efcae784d7b4f2f2f80";
`
They is a new instance of an Ethereum contract. Ethers.js doesn't automatically register the contraction with the Etherum network. To an interact for a contraction for your local hardhat network, you have to have to have up your methods and the "cal"
The solution:
To 10, 2013,
`JavaScript
Contractor = new contract (account0);
`
It is a new contracts instance the available account eddress. You also to call up the "Call" function of Ethers.js in order to carry out of method in the contract instace.
Example code:
Gere is an updated examplee you can declare a contractor instalogy and chall your methods with Ethers.js:
`JavaScript
Const {Ethers} = request ("Hardhat");
// Define the contraact ABI (application binary interface)
Const Abi = [
{
Entries: [],
Statematability: "View",
Type: "Function"
},
{
Inputs: ["String", "Int", "Boolean"],
Statematability: "Writing",
Type: "Function"
}
];
// Create a new contracts instance with a hardhat
Asynchrical function main () {
Const account0 = "0xac0974bec39a17e3ba4a6b4a6b4d238ff944bacb4efcae784d7b4f2f2f80";
Const Contractinstance = expected from Ethers.Getcontractory ("yourCONTRACTNAME");
Const contract = wait for contraactstance.deploy (account0);
// Call a method in the contraction bodi
Const resources = act on contraact.methods.yourmethod (). Call ();
console.log (result); // edition: Your return value
// Delete the contractual instance
Wait for contraact.destroy ();
}
// execute the main
Primarly();
`
Diploma:
In this article, we have emphasized an essential step intelligent contractions on the Etherum blockchain uss. By locing a new contract instance and calling its methods, you can carry out varius action in you local hardhat network.
Remember to update your code accordingly to veriable "Contract Instance" during your function. Happy coding!