4

I'm working on ethers npm package and after instantiating wallet, I'm trying to transfer some tokens to the address. but it is throwing out an error missing-signer.

Do anyone know, what mistake I might have done?

My Code :

var ethers = require('ethers');
var providers = require('ethers').providers;
var utils = require('ethers').utils;
var p = new providers.JsonRpcProvider('http://xxx.xx.xxx.xx:8545', false, 5);
ethers.Wallet.provider=p;

const contractAddress = '0x contract address here';
var contractInterface = 'contract interface here';

var data = 'wallet json from keystore';

var walletJson = JSON.stringify(data);
var wPassword='keystore account password';
ethers.Wallet.fromEncryptedWallet(walletJson, wPassword).then(function(wallet) {
    console.log("Address: " + wallet.address);    

    var address = 'adress to transfer to';
    // //var payout =  ethers.utils.parseEther('10.0');
    var payout =  1000000000;
    var contract = new ethers.Contract(contractAddress, contractInterface, wallet);

    try {
        var promise = contract.functions.transfer(address, payout);
        console.log(promise);

        promise
        .then(function(result) { 
          console.log(result); 
        })
        .catch(function(err) { 
          console.log("Promise Rejected "+ err); 
        });
    } catch (e) { 
      console.log(e); process.exit(); 
    }
}).
catch(function(err){
    console.log(err);
});

Is there anything I'm doing wrong with the account address or password(contract address)?

What might the mistake be? Any ideas?

2
  • You ever figure this out?
    – wuno
    Feb 7 '18 at 4:47
  • it's either the contract address or the interface is wrong! you might also need to check the walletjson for that account.
    – RealSteel
    Feb 7 '18 at 6:21
3

The problem is that the wallet instance does not have provider, so when passing it into the Contract constructor, it does not realize it is a Signer, and not just a Provider.

After decrypting the wallet instance, make sure you set the provider on it (before passing it into the Contract constructor):

wallet.provider = p;

Setting a provider on the global Wallet class won't affect instances.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.