Lesson: 5 With Alchemy I can't recognise the retrieve() method, it throws error Bad-Data #4842
-
Hello guys I'm having this problem can't figure out why. Alchemy can not decode the retrieve() method hence the can;'t display initial favoriteNumber 0 and new stored number either. Here is the error message below:
Below is the code: async function main() {
// 127.0.0.1:7545
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
// const encryptedJson = fs.readFileSync("./.encryptedKey.json", "utf8");
// let wallet = ethers.Wallet.fromEncryptedJsonSync(
// encryptedJson,
// process.env.PRIVATE_KEY_PASSWORD
// );
// wallet = await wallet.connect(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("Started deployong your contract, please wait...")
const contract = await contractFactory.deploy();
await contract.deploymentTransaction;
// console.log(`Contract Address: ${await contract.getAddress()}`)
//Get number
const currentFavoriteNumber = await contract.retrieve();
console.log(`Current favorite number is, ${currentFavoriteNumber.toString()}`);
const transactionResponse = await contract.store("7",);
await transactionResponse;
const updatedFavoriteNumber = await contract.retrieve();
console.log(`Updated favorite number is: ${updatedFavoriteNumber}`)
} |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Feb 17, 2023
Replies: 1 comment 4 replies
-
@NodEm9 try this; const currentFavoriteNumber = (await contract.retrieve()).toString() |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
alymurtazamemon
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@NodEm9 try this;