4

The example code for eth-lightwallet that shows how to use it with the hooked web3 provider can be configured to use the local node as follows:

var ethClient = "http://localhost:1111";
var web3 = new Web3();
var global_keystore;

function setWeb3Provider(keystore) {

    var web3Provider = new HookedWeb3Provider({
        host: ethClient,
        transaction_signer: keystore;
    });

    web3.setProvider(web3Provider);

}

The example_usage.js that demonstrates the use of txutils however does not show how the eth node can be set. Can anyone advise?

example_usage.js starts...

// Example usage: Name Registry
// Create the contract, register the key 123, set the value 456

var lightwallet = require('../index.js')
var txutils = lightwallet.txutils
var signing = lightwallet.signing
var encryption = lightwallet.encryption
.....
2

They are two different approaches. The first one, with hooked web3 provider, it means that you use a normal Web3 provider but delegating the signing behavior to something else (in your example the keystore).

The Hooked Web3 Provider is a normal HTTP Web3 provider that allows you to "hook in" an external transaction signer that can be used to sign transactions for accounts not managed by the Ethereum client (i.e., aren't managed by geth). An example transaction signer might be an external program or device that manages its own accounts and private keys. Together, the transaction signer and the web3 provider will use the Ethereum client to place signed transactions on the network.

txutils libray on the contrary is useful especially when you want to use a classic web3 provider. In this case, you can prepare and sign the transaction with txutils, reference Web3 and attach to the node as usual

if (typeof web3 !== 'undefined') {
  web3 = new Web3(web3.currentProvider);
} else {
  // set the provider you want from Web3.providers
  web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}

and then you can use the web3.eth.sendRawTransaction method

web3.eth.sendRawTransaction(signedTransactionData [, callback])

to send the txns to the network.

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.