0

I need to sign a transaction and send to infura using a keystore. I ran into the following error while calling the decrypt function.

if (json.crypto.kdf === 'scrypt') {
                ^
TypeError: Cannot read property 'kdf' of undefined
at Accounts.decrypt

I am using web3 v1.0.0-beta.36

This is my code

const Web3 = require('web3');
const Tx = require('ethereumjs-tx')
const web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/v3/f..."));
var fs = require('fs');

const contractAddress = "0x...";
const sendingAccount = "0x...";
const password = "...";

var abiArray = JSON.parse(getAbi());
var contract = new web3.eth.Contract(abiArray,contractAddress);

const keystore = fs.readFileSync("UTC--...", 'utf8');
const decryptedAccount = 
web3.eth.accounts.decrypt(JSON.parse(keystore), password);
TylerH
  • 20,799
  • 66
  • 75
  • 101
Morris
  • 169
  • 8
  • Is this line your code? If not, find which call creates this error. If yes, please post the code of how you read this json. Also what platform(web, mobile, etc) is this written for? – nikos fotiadis Nov 21 '18 at 17:47
  • The line generating the error is `web3.eth.accounts.decrypt(JSON.parse(keystore), password);` – Morris Nov 21 '18 at 22:27
  • Well by the error it seems like the keystore is not formed correctly. Can you debug to see what the keystore object is before you call decrypt? Here is an example of what it should look like: https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#wallet-decrypt – nikos fotiadis Nov 22 '18 at 07:05
  • Is the function `web3.eth.accounts.decrypt` the same as `web3.eth.accounts.wallet.decrypt`? – Morris Nov 22 '18 at 08:28
  • Sorry. Here is the correct link https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#decrypt . But the point here is see if the keystone object is correct. – nikos fotiadis Nov 22 '18 at 10:57
  • Does this answer your question? [How to avoid 'cannot read property of undefined' errors?](https://stackoverflow.com/questions/14782232/how-to-avoid-cannot-read-property-of-undefined-errors) – TylerH Feb 17 '23 at 22:14

0 Answers0