0

I have smart contract deployed that accepts funds (via fallback function function() payable { ... }). Also I have frontend using web3 to send funds.

When I tested it with local node (and JSON wallets presented locally) evrything works fine - web3.personal.unlockAccount(account, password) unlocked account with data provided by user then funds sent to contract.

Now I deployed geth node on standalone VPS and connecting to it using code:

var Web3 = require('web3');
this.web3 = new Web3();
this.web3.setProvider(new Web3.providers.HttpProvider('http://my-node-addr.net:18545/'));

if(this.web3.isConnected()) {
  console.log('web3 connected');
} else {
  console.log('web3 NOT connected');
}

It shows that client connected successfully. But when I am trying to send funds code failed on line

web3.personal.unlockAccount(account, password);

with error Error: no key for given address or file. Of course, my node cannot contain all client's wallet file (nobody want to upload it).

Here is how I am sending transaction:

this.contract.sendTransaction({ from: account, value: amount, gas: 400000 })
.then(() => {
    // OK, everything fine!
})
.catch(error => {
    // I am here
    console.log('Oops...', 'Error happened during your payment: ' + error, 'error');
});

UPD: What I want: provide html page with fields "account", "password" and "amount" that allows users to send ethers to predefined address. Of course my node will not have UTC-..... files (wallets).

4
  • 1
    Have you considered to use MetaMask browser plugin to store client's wallets and send transactions from client side? You don't need to unlock any account in this case. Maybe, it helps to you. Commented Jul 25, 2017 at 5:38
  • Possible duplicate of Unlocking accounts and making transactions in web3.js
    – niksmac
    Commented Jul 25, 2017 at 5:49
  • @ViktorBaranov I do not want to force clients to install pugins, chrome browser or anything else. All I want is to provide html page with "account" and "password" fields that allows users to sends etheres to predefined account.
    – Alex G.P.
    Commented Jul 25, 2017 at 6:26
  • @niksmac that question is totally unrelated because that OP hasn't any problems with unlocking accounts and as I see he means accounts whose wallets presented on target node. My question is about unlocking accounts whose wallets not presented on node.
    – Alex G.P.
    Commented Jul 25, 2017 at 6:28

1 Answer 1

2

The method sendTransaction works because geth has access to the private key. In your scenario since the private key is in the client geth has no access to it and will not be able to sign the transaction.

You need to sign the transaction in the client side and use sendRawTransaction to broadcast your signed transaction. You can use eth-lightwallet to manage keys client side, if you want something more low level you can use ethereumjs-tx to create and sign your own transactions.

2
  • To sign raw trasaction I need private key from user, right?
    – Alex G.P.
    Commented Jul 26, 2017 at 4:11
  • Yes, you need the user private key.
    – Ismael
    Commented Jul 26, 2017 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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