Creating offline Ethereum transactions in JavaScript

By no-reply Jun 30, 2017 7:30 AM EST

This story was shared from this site

Preface

In this blog post we show how to create Ethereum blockchain transactions programmatically in JavaScript and offline. This is the second part of tutorial blog posts continuing the earlier Ethereum JavaScript tutorial left.

We bend the meaning of the word offline here a bit. We still communicate with Ethereum network to get the gas cost and the next transaction nonce. However, the private key never leaves the computer.

This blog post serves mostly as an example. Advanced users can use the script presented here for doing Ether cold wallet and offline transactions.

Ethereum transaction dissemination

Each Ethereum transaction consists of

Target address, either a contract or an Ethereum account.

Nonce, incremented once per transaction per account, to prevent double spend attacks.

Value, how many Ethers are transferred. Can be 0 for contract calls, but you still need to pay for the gas.

The maximum gas the transaction is allowed pull from the sending account.

The gas price if the transaction needs a preferential treatment.

Optional data payload that would include any function call and arguments encoded.

Transaction is signed with the private key of the sending account address. Based on these arguments you can create a raw transaction, as a hex string, that can be pushed to the network.

Pushing can happen either through EtherScan.io service or through web3.eth.sendRawTransaction API.

Furthermore in this particular example we also need

EtherScan.io API key – we use their API to communicate with the network Example script

The example script is available on TokenMarket Github repository.

To run the script

You need to understand Node.js and Babel basic

Node 7 or newer

Clone the git repository

Install dependencies with

Facebook Comments


Comments are closed here.

Read previous post:
Bitquence , novice and mobile friendly crypto investing service, featured on Forbes

An initiative targeting mainstream consumers with a “user-friendly crypto wallet” and touted powerful features to enhance accessibility, Bitquence today launched...

Close