国内最大的c2c网站是,cms网站建设有多少条数据,企业网站建设 建立作用,图行天下免费素材网报这种错误#xff1a;一般在生成private key前面添加0x即可解决。我就是在私钥前面添加了0x解决了。
在学习web3时#xff0c;使用助词生成的私钥#xff0c;然后由私钥导出keystore就报错#xff1a;
ERROR
Invalid Private Key, Not a valid …报这种错误一般在生成private key前面添加0x即可解决。我就是在私钥前面添加了0x解决了。
在学习web3时使用助词生成的私钥然后由私钥导出keystore就报错
ERROR
Invalid Private Key, Not a valid string or uint8Array
InvalidPrivateKeyError: Invalid Private Key, Not a valid string or uint8Arrayat parseAndValidatePrivateKey (webpack-internal:///./node_modules/web3-eth-accounts/lib/esm/account.js:132:11)at eval (webpack-internal:///./node_modules/web3-eth-accounts/lib/esm/account.js:523:32)at Generator.next (anonymous)at eval (webpack-internal:///./node_modules/web3-eth-accounts/lib/esm/account.js:66:67)at new Promise (anonymous)at __awaiter (webpack-internal:///./node_modules/web3-eth-accounts/lib/esm/account.js:48:10)at Object.encrypt (webpack-internal:///./node_modules/web3-eth-accounts/lib/esm/account.js:521:52)at genMnemonic (webpack-internal:///./node_modules/unplugin/dist/webpack/loaders/transform.js?unpluginNameunplugin-vue-components!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/components/AccountSys.vue?vuetypescriptsetuptruelangjs:46:42)
开始报错以为是自己没开梯子,但我用之前写的demo是能查询到eth账户余额于是根据报错信息怀疑是生成的privatekey不对我照着学习的视频检查了代码跟它一样没问题呀然后我在生成的私钥前面添加了0x就可以了。
//获取钱包私钥const privateKeywallet.getPrivateKey().toString(hex);
const web3 new Web3(Web3.givenProvider || wss://sepolia.infura.io/ws/v3/018c25a8b5ce4f23810c49f60478471f);const keystore web3.eth.accounts.encrypt(0xprivateKey,111111);
搞定。