Consensys / eth-lightwallet

Lightweight JS Wallet for Node and the browser
MIT License
1.47k stars 503 forks source link

this.passwordProvider is not a function at KeyStore.signTransaction #177

Closed DalderupMaurice closed 6 years ago

DalderupMaurice commented 6 years ago

I tried to send a transaction to a smart contract using Infura, but whenever I try to send the transaction I get the following error:

Uncaught TypeError: this.passwordProvider is not a function
    at KeyStore.signTransaction (keystore.js:653)
    at hooked-web3-provider.js:187
    at hooked-web3-provider.js:158
    at XMLHttpRequest.request.onreadystatechange (httpprovider.js:114)

I am using web3@1.0.0-beta26 and the issue occurred on both eth-lightwallet version 3.0.0 and 2.5.6.

The error was triggered on this piece of code:

ContractInstance.methods.sendCoin(receiver, amount, reason).send({from: sender})
      .on('transactionHash', function(hash){
        console.log('hash', hash);
      })
      .on('confirmation', function(confirmationNumber, receipt){
        console.log('confirmationNumber', confirmationNumber);
      })
      .on('receipt', function(receipt){
        console.log('receipt', receipt);
      })
      .on('error', (err) => {
        console.log("err", err);
      });

On a sidenote, I am not sure if this is due to the use of hooked-web3-provider. My initialisation of web3 looks something like this:

let initWeb3 = (password, seed) => new Promise(function (resolve, reject) {
    let results;
    let web3 = window.web3;

    lightwallet.keystore.createVault({
        password: password,
        seedPhrase: seed, // Optionally provide a 12-word seed phrase
        hdPathString: "m/44'/60'/0'/0" // Optional custom HD Path String
    }, function (err, ks) {

        if (err) {
            console.log(err);
            reject("Wrong password");
        }

        ks.keyFromPassword(password, (err, pwDerivedKey) => {
            if (err) throw err;

            ks.generateNewAddress(pwDerivedKey, 1);

            let eth_address = ks.getAddresses()[0];
            window.localStorage.setItem("eth_address", eth_address);

            ks.passwordProvider = password;

            let provider = new HookedWeb3Provider({
                host: process.env.RPC_URL,
                transaction_signer: ks
            });

            web3 = new Web3(provider);

            results = {
                web3: web3
            };

            console.log("Injected signed web3", web3);
            resolve(results)
        });
    });
});
AbdelrhmanAbdelhamed commented 6 years ago

Function KeyStore.prototype.passwordProvider(callback) The function passwordProvider is an async function that calls the callback(err, password) with a password supplied by the user or by other means. The user of the hooked web3-provider is encouraged to write their own passwordProvider.

Here's the default function definition:

KeyStore.prototype.passwordProvider = function (callback) { var password = prompt("Enter password to continue", "Enter password"); callback(null, password); };

DalderupMaurice commented 6 years ago

Thanks for the reply! I have already figured it out in the meanwhile, but that was indeed my fault.

I have replaced "password" with a function, returning callback(null, password); and it now works perfectly.