Package Exports
- ethereumjs-tx
- ethereumjs-tx/ecdsaOps.js
- ethereumjs-tx/ecdsaOpsBrowser.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ethereumjs-tx) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ETHEREUMJS-TX
A simple module for creating, manipulating and signing Ethereum transactions.
STATUS
CONTACT
Scrollback or #ethereumjs on freenode
INSTALL
npm install ethereumjs-tx
USAGE
var Tx = require('ethereumjs-tx');
var privateKey = new Buffer('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex');
var rawTx = {
nonce: '00',
gasPrice: '09184e72a000',
gasLimit: '2710',
to: '0000000000000000000000000000000000000000',
value: '00',
data: '7f7465737432000000000000000000000000000000000000000000000000000000600057'
};
var tx = new Tx(rawTx);
tx.sign(privateKey);
var serializedTx = tx.serialize();
API
Transaction
new Transaction([data])
Transaction
PropertiesTransaction
Methodstransaction.serialize()
transaction.hash([signature])
transaction.sign(privateKey)
transaction.getSenderAddress()
transaction.getSenderPublicKey()
transaction.validate()
transaction.validateSignature()
transaction.getDataFee()
transaction.getBaseFee()
transaction.getUpfrontCost()
transaction.toJSON([object])
Transaction
Implements schema and functions relating to Ethereum transactions
new Transaction([data])
Creates a new transaction object
data
- a transaction can be initiailized with either abuffer
containing the RLP serialized transaction or anarray
of buffers relating to each of the tx Properties, listed in order below. For example.
var rawTx = {
nonce: '00',
gasPrice: '09184e72a000',
gasLimit: '2710',
to: '0000000000000000000000000000000000000000',
value: '00',
data: '7f7465737432000000000000000000000000000000000000000000000000000000600057',
v: '1c',
r: '5e1d3a76fbf824220eafc8c79ad578ad2b67d01b0c2425eb1f1347e8f50882ab',
s '5bd428537f05f9830e93792f90ea6a3e2d1ee84952dd96edbae9f658f831ab13'
};
var tx = new Transaction(rawTx);
Or lastly an Object
containing the Properties of the transaction like in the Usage example
For Object
and Arrays
each of the elements can either be a Buffer
, hex String
, Number
, or an object with a toBuffer
method such as Bignum
transaction
Properties
raw
- The raw rlp decoded transaction.nonce
to
- the to addressvalue
- the amount of ether sentdata
- this will contain thedata
of the message or theinit
of a contract.v
- EC signature parameterr
- EC signature parameters
- EC recovery ID
Transaction
Methods
transaction.serialize()
Returns the RLP serialization of the transaction
Return: 32 Byte Buffer
transaction.hash([signature])
Returns the SHA3-256 hash of the rlp transaction
Parameters
signature
- aBoolean
determining if to include the signature components of the transaction. Defaults to true.
Return: 32 Byte Buffer
transaction.sign(privateKey)
Signs the transaction with the given privateKey.
Parameters
privateKey
- a 32 ByteBuffer
transaction.getSenderAddress()
Returns the senders address
Return: 20 Byte Buffer
transaction.getSenderPublicKey()
returns the public key of the sender
Return: Buffer
transaction.validate()
Determines if the transaction is schematicly valid by checking its signature and gasCost.
Return: Boolean
transaction.validateSignature()
Determines if the signature is valid
Return: Boolean
transaction.getDataFee()
Returns the amount of gas to be paid for the data in this transaction
Return: bn.js
transaction.getBaseFee()
Returns the minimum amount of gas the tx must have (DataFee + TxFee)
Return: bn.js
transaction.getUpfrontCost()
The total amount needed in the account of the sender for the transaction to be valid
Return: bn.js
transaction.toJSON([object])
Returns transaction as JSON
Parameters
object
- aBoolean
that defaults to false. Ifobject
is true then this will return an object else it will return anarray
Return: Object
or Array
TESTS
test uses mocha. To runnpm test