lesson 5 updateFavoriteNumber #3194
-
Hello fellow Students, I have a question regarding the updateFavoriteNumber I think it's going to be a simple one and just a silly noob question on my part, but once updating FavoriteNuber I notice that in Ganache that there is a contract call and contract creation every time I updateFavoriteNumber is this normal? I'm thinking not because the gas price will be insane. 7:33:00 youtube const ethers = require("ethers");
const fs = require("fs-extra");
async function main() {
const provider = new ethers.providers.JsonRpcProvider(
"i have deleted the wallet address just out of habit "
);
const wallet = new ethers.Wallet(
"", // its a big no no to put private keys in code
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(); // stop here wait for contract to deploy
await contract.deployTransaction.wait(1); // <-- this goes down
const currentFavoriteNumber = await contract.retrieve();
console.log(`Current Favorite Number: ${currentFavoriteNumber.toString()}`);
const transactionResponse = await contract.store("8");
const transactionReceipt = await transactionResponse.wait(1);
const updatedFavoriteNumber = await contract.retrieve();
console.log(`Updated favorite number is: ${updatedFavoriteNumber}`);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@Themorningcormorant Actually here you are running the whole script that includes the deploy part, later you will learn about deploying scripts and running scripts separately. |
Beta Was this translation helpful? Give feedback.
@Themorningcormorant Actually here you are running the whole script that includes the deploy part, later you will learn about deploying scripts and running scripts separately.