const { ethers, run, network } = require("hardhat")
require("dotenv").config()
async function main() {
const SimpleStorageFactory = await ethers.getContractFactory(
"SimpleStorage"
)
console.log("Deploying contract...")
const simpleStorage = await SimpleStorageFactory.deploy()
const simpleStoragetrans = await SimpleStorageFactory.getDeployTransaction()
console.log("simpleStorage:sss:", simpleStorage)
console.log("simpleStoragetrans:sss:", simpleStoragetrans)
const contractAddress = await simpleStorage.getAddress()
console.log("contractAddress:sss:", contractAddress)
console.log("network.name:sss", network.name)
if (network.name == "sepolia" && process.env.ETHERSCAN_API_KEY) {
// await verify(contractAddress, [])
}
const currentValue = await simpleStorage.retrieve()
const sendValue = ethers.parseEther("800")
//updatevalue
await simpleStorage.store(sendValue)
const newValue = await simpleStorage.retrieve()
console.log(newValue)
}
async function verify(contractAddress, args) {
console.log("verify Contract")
// npx hardhat verify --network sepolia 0xxxxxxxxx8EbEf80F0008c16b0ABFc4D6a
try {
await hre.run("verify:verify", {
address: contractAddress,
constructorArguments: args,
})
} catch (error) {
console.log("Contract verify error:", error)
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
Error displayed on line 20:
const currentValue = await simpleStorage.retrieve()
The strange thing is that it's normal for me to use the local hardhat network,I only report an error when using sepolia。
error desc
Error: could not decode result data (value="0x", info={ "method": "retrieve", "signature": "retrieve()" }, code=BAD_DATA, version=6.11.1)
at makeError (/Users/daiwenxiong/BEAR_FILE/PROJECT/WEB3_PROJECT/LEARN_CHAINLINK_HARDHAT/node_modules/ethers/src.ts/utils/errors.ts:694:21)
at assert (/Users/daiwenxiong/BEAR_FILE/PROJECT/WEB3_PROJECT/LEARN_CHAINLINK_HARDHAT/node_modules/ethers/src.ts/utils/errors.ts:715:25)
at Interface.decodeFunctionResult (/Users/daiwenxiong/BEAR_FILE/PROJECT/WEB3_PROJECT/LEARN_CHAINLINK_HARDHAT/node_modules/ethers/src.ts/abi/interface.ts:916:15)
at staticCallResult (/Users/daiwenxiong/BEAR_FILE/PROJECT/WEB3_PROJECT/LEARN_CHAINLINK_HARDHAT/node_modules/ethers/src.ts/contract/contract.ts:346:35)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at staticCall (/Users/daiwenxiong/BEAR_FILE/PROJECT/WEB3_PROJECT/LEARN_CHAINLINK_HARDHAT/node_modules/ethers/src.ts/contract/contract.ts:303:24)
at Proxy.retrieve (/Users/daiwenxiong/BEAR_FILE/PROJECT/WEB3_PROJECT/LEARN_CHAINLINK_HARDHAT/node_modules/ethers/src.ts/contract/contract.ts:351:41)
at main (/Users/daiwenxiong/BEAR_FILE/PROJECT/WEB3_PROJECT/LEARN_CHAINLINK_HARDHAT/scripts/deploy.js:20:26) {
code: 'BAD_DATA',
value: '0x',
info: { method: 'retrieve', signature: 'retrieve()' },
shortMessage: 'could not decode result data'
}
I did not find the reason in any document.
I hope someone can help me. Thank you very much
I rewrote the main method
It was successful