2

I am working on a iOS & Android-App which is interacting with the blockchain via a Geth node behind an API. Is it possible to do the following: 1. generate an address using a package like EthereumJS 2. Sign transactions with it 3. Accept those transactions with the Geth node?

Or is it only possible to generate addresses from a Geth-Node? Thank you!

1 Answer 1

3
  1. Yes, you can use ethereumjs-wallet to create a wallet client side.

    const wallet = require('ethereumjs-wallet');
    const myWallet = wallet.generate();
    
    console.log(`Address: ${myWallet.getAddressString()}`);
    console.log(`Private Key: ${myWallet.getPrivateKeyString()}`)
    

    Will output something like this:

    Address: 0x31483bb3cae99bf173e5f61f0c62dc398f197b81
    Private Key: 0x96d99fefd214a6cf0e401936bed52c96ddbb82b7e2d51d453ae7b85f115ae20a
    
  2. You can use ethereumjs-tx to create and sign transactions.

    const Transaction = require('ethereumjs-tx');
    
    const txData = {
      nonce: '0x00',
      gasPrice: '0x04a817c800',
      gasLimit: '0x5208',
      to: '0x31483bb3cae99bf173e5f61f0c62dc398f197b81',
      value: '0x03e8',
      data: '0x',
      chainId: 3
    };
    
    const tx = new Transaction(txData);
    tx.sign(myWallet.getPrivateKey());
    
  3. To send signed transaction to geth you can use web3.eth.sendRawTransaction.

    web3.eth.sendRawTransaction('0x'+tx.serialize().toString('hex'));
    
0

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.