TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider') Edit: (typo) #4683
-
Deploy.js const ethers = require("ethers")
const fs = require("fs")
require("dotenv").config()
async function main() {
let provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL)
let wallet = new ethers.Wallet(process.env.PRIVATE_KEY, 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 contractFacotry.deploy()
const deploymentReceipt = await contract.deployTransaction.wait(1)
console.log(`Contract deployed to ${contract.address}`)
let currentFavoriteNumber = await contract.retrieve()
console.log(`Current Favorite Number: ${currentFavoriteNumber}`)
console.log("Updating favorite number...")
let transactionResponse = await contract.store(7)
let transactionReceipt = await transactionResponse.wait()
currentFavoriteNumber = await contract.retrieve()
console.log(`New Favorite Number: ${currentFavoriteNumber}`)
}
main()
.then(() => ProcessingInstruction.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
}) Package.json {
"packageManager": "yarn@3.4.0",
"dependencies": {
"dotenv": "^16.0.3",
"ethers": "^5.7.2",
"fs-extra": "^11.1.0",
"ganache": "^7.7.3",
"solc": "0.8.7-fixed"
},
"name": "solidity",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"compile": "yarn solcjs --bin --abi --include-path node_modules/ --base-path . -o . SimpleStorage.sol",
"start": "node deploy.js"
},
"author": "",
"license": "ISC",
"description": "First locally run solidty code!!!"
} Terminal ERROR when node deploy.js is used Error: invalid hexlify value (argument="value", value="0x9d9b56ac5c33685f0b5d71106c73c8bb08fdbbe8263887a896a20d950e258018;", code=INVALID_ARGUMENT, version=bytes/5.7.0)
at Logger.makeError (/root/Solidity/node_modules/@ethersproject/logger/lib/index.js:238:21)
at Logger.throwError (/root/Solidity/node_modules/@ethersproject/logger/lib/index.js:247:20)
at Logger.throwArgumentError (/root/Solidity/node_modules/@ethersproject/logger/lib/index.js:250:21)
at hexlify (/root/Solidity/node_modules/@ethersproject/bytes/lib/index.js:200:19)
at new SigningKey (/root/Solidity/node_modules/@ethersproject/signing-key/lib/index.js:20:82)
at new Wallet (/root/Solidity/node_modules/@ethersproject/wallet/lib/index.js:120:36)
at main (/root/Solidity/deploy.js:8:18)
at Object.<anonymous> (/root/Solidity/deploy.js:28:1)
at Module._compile (node:internal/modules/cjs/loader:1246:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1300:10) {
reason: 'invalid hexlify value',
code: 'INVALID_ARGUMENT',
argument: 'value',
value: '0x9d9b56ac5c33685f0b5d71106c73c8bb08fdbbe8263887a896a20d950e258018;'
}
How to solve this error? |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Feb 2, 2023
Replies: 1 comment
-
@Tanish32 Make sure you do not have semi-colon at the end of private key |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Tanish32
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Tanish32 Make sure you do not have semi-colon at the end of private key
0x9d9b56ac5c33685f0b5d71106c73c8bb08fdbbe8263887a896a20d950e258018;
as we can see here.