I am trying to build a website that will allow multiple users to send Ethereum transactions without having to install a node. My server is running a node, which is configured to accept requests from any internet address, and it seems that I should be able to connect to the node from any device through a web browser. Is the Ethereum JavaScript API useful to doing this? Thank you!
2 Answers
Yes, you can use web3.ETH.sendTransaction
to Sends a transaction to the network.
web3.eth.sendTransaction(transactionObject [, callback])
Example
// compiled solidity source code using https://chriseth.github.io/cpp-ethereum/
var code = "603d80600c6000396000f3007c01000000000000000000000000000000000000000000000000000000006000350463c6888fa18114602d57005b6007600435028060005260206000f3";
web3.eth.sendTransaction({data: code}, function(err, address) {
if (!err)
console.log(address); // "0x7f9fade1c0d57a7af66ab4ead7c2eb7b11a91385"
});
-
This question does not answer regarding if you need or don't need a node running on users' side Commented Jul 19, 2016 at 16:25
-
@MikkoOhtamaa Why not? web3 can connect to any node right?– niksmacCommented Jul 19, 2016 at 16:32
-
Are you saying one should run publicly facing Ethereum node allowing RPC connections from any host? As far as I know running public RPC interface is highly discouraged due to security implications. Commented Jul 19, 2016 at 17:11
-
@MikkoOhtamaa yeah, i am aware of that. OP is not asking or seems to be worried about that.– niksmacCommented Jul 19, 2016 at 17:14
Set up your node, then create a public facing api that accepts signed raw transactions input. You could do this with hooked web3 and your users could use eth-lightwallet by ConsenSys.
signing.signTx(keystore, pwDerivedKey, rawTx, signingAddress, hdPathString)
Signs a transaction with the private key corresponding to signingAddress.
Inputs
- keystore: An instance of the keystore with which to sign the TX with.
- pwDerivedKey: the users password derived key (Uint8Array)
- rawTx: Hex-string defining an RLP-encoded raw transaction.
- signingAddress: hex-string defining the address to send the transaction from.
- hdPathString: (Optional) A path at which to create the encryption keys.
Return value
Hex-string corresponding to the RLP-encoded raw transaction.