Class: Transaction

Transaction


new Transaction(options)

Transaction constructor. Class encapsulate main operation with transactions.
Parameters:
Name Type Description
options TransactionOptions Transaction options.
See:
Example
var acc = Account.NewAccount();

var tx = new Transaction({
   chainID: 1,
   from: acc,
   to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17",
   value: 10,
   nonce: 12,
   gasPrice: 1000000,
   gasLimit: 2000000,
   contract: {
       function: "save",
       args: "[0]"
   }
});

Methods


<static> recover(message, signature)

Transaction recover method.
Parameters:
Name Type Description
message String/Hash Transaction hash.
signature String/Hash Transaction sign
Returns:
Transaction from address public key.
Type
Hash
Example
var pubKey = Transaction.recover("82bc718bfd24392b3872eb5a874927a327ab19b156c5584bd5f93b08fab5b1a2", "003d4064f16cbc72367b0fa3870bdcd1044bdb166019d87cdaac6dcfb8c09ac9471570e5b2e1dc249a8642ba67e585e3f43e6383c3b87532f5eb1fe2e718a5ab00");

<static> fromProto(data)

Transaction fromProto method, parse rawData to transaction object.
Parameters:
Name Type Description
data String/Hash Transaction raw data.
Returns:
Transaction object.
Type
Object
Example
var tx = Transaction.fromProto("EhjZTY/gKLhWVVMZ+xoY9GiHOHJcxhc4uxkaGNlNj+AouFZVUxn7Ghj0aIc4clzGFzi7GSIQAAAAAAAAAAAN4Lazp2QAACgBMPCz6tUFOggKBmJpbmFyeUDpB0oQAAAAAAAAAAAAAAAAAA9CQFIQAAAAAAAAAAAAAAAAAABOIA==");

hashTransaction()

Convert transaction to hash by SHA3-256 algorithm.
Returns:
hash of Transaction.
Type
Hash
Example
var acc = Account.NewAccount();

var tx = new Transaction({
   chainID: 1,
   from: acc,
   to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17",
   value: 10,
   nonce: 12,
   gasPrice: 1000000,
   gasLimit: 2000000
});
var txHash = tx.hashTransaction();
//Uint8Array(32) [211, 213, 102, 103, 23, 231, 246, 141, 20, 202, 210, 25, 92, 142, 162, 242, 232, 95, 44, 239, 45, 57, 241, 61, 34, 2, 213, 160, 17, 207, 75, 40]

signTransaction()

Sign transaction with the specified algorithm.
Example
var acc = Account.NewAccount();

var tx = new Transaction({
   chainID: 1,
   from: acc,
   to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17",
   value: 10,
   nonce: 12,
   gasPrice: 1000000,
   gasLimit: 2000000
});
tx.signTransaction();

toPlainObject()

Conver transaction data to plain JavaScript object.
Returns:
Plain JavaScript object with Transaction fields.
Type
Object
Example
var acc = Account.NewAccount();
var tx = new Transaction({
   chainID: 1,
   from: acc,
   to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17",
   value: 10,
   nonce: 12,
   gasPrice: 1000000,
   gasLimit: 2000000
});
txData = tx.toPlainObject();
// {chainID: 1001, from: "n1USdDKeZXQYubA44W2ZVUdW1cjiJuqswxp", to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17", value: 1000000000000000000, nonce: 1, …}

toString()

Convert transaction to JSON string.
Note: Transaction should be sign before converting.
Returns:
JSON stringify of transaction data.
Type
String
Example
var acc = Account.NewAccount();

var tx = new Transaction({
   chainID: 1,
   from: acc,
   to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17",
   value: 10,
   nonce: 12,
   gasPrice: 1000000,
   gasLimit: 2000000
});
tx.signTransaction();
var txHash = tx.toString();
// "{"chainID":1001,"from":"n1QZMXSZtW7BUerroSms4axNfyBGyFGkrh5","to":"n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17","value":"1000000000000000000","nonce":1,"timestamp":1521905294,"data":{"payloadType":"binary","payload":null},"gasPrice":"1000000","gasLimit":"20000","hash":"f52668b853dd476fd309f21b22ade6bb468262f55402965c3460175b10cb2f20","alg":1,"sign":"cf30d5f61e67bbeb73bb9724ba5ba3744dcbc995521c62f9b5f43efabd9b82f10aaadf19a9cdb05f039d8bf074849ef4b508905bcdea76ae57e464e79c958fa900"}"

toProto()

Convert transaction to Protobuf format.
Note: Transaction should be sign before converting.
Returns:
Transaction data in Protobuf format
Type
Buffer
Example
var acc = Account.NewAccount();

var tx = new Transaction({
   chainID: 1,
   from: acc,
   to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17",
   value: 10,
   nonce: 12,
   gasPrice: 1000000,
   gasLimit: 2000000
});
tx.signTransaction();
var txHash = tx.toProto();
// Uint8Array(127)

toProtoString()

Convert transaction to Protobuf hash string.
Note: Transaction should be sign before converting.
Returns:
Transaction string.
Type
Base64
Example
var acc = Account.NewAccount();

var tx = new Transaction({
   chainID: 1,
   from: acc,
   to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17",
   value: 10,
   nonce: 12,
   gasPrice: 1000000,
   gasLimit: 2000000
});
tx.signTransaction();
var txHash = tx.toProtoString();
// "EhjZTY/gKLhWVVMZ+xoY9GiHOHJcxhc4uxkaGNlNj+AouFZVUxn7Ghj0aIc4clzGFzi7GSIQAAAAAAAAAAAN4Lazp2QAACgBMPCz6tUFOggKBmJpbmFyeUDpB0oQAAAAAAAAAAAAAAAAAA9CQFIQAAAAAAAAAAAAAAAAAABOIA=="

fromProto()

Restore Transaction from Protobuf format.
Properties:
Name Type Description
data Buffer | String Buffer or stringify Buffer.
Returns:
Restored transaction.
Type
Transaction
Example
var acc = Account.NewAccount();

var tx = new Transaction({
   chainID: 1,
   from: acc,
   to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17",
   value: 10,
   nonce: 12,
   gasPrice: 1000000,
   gasLimit: 2000000
});
var tx = tx.fromProto("EhjZTY/gKLhWVVMZ+xoY9GiHOHJcxhc4uxkaGNlNj+AouFZVUxn7Ghj0aIc4clzGFzi7GSIQAAAAAAAAAAAN4Lazp2QAACgBMPCz6tUFOggKBmJpbmFyeUDpB0oQAAAAAAAAAAAAAAAAAA9CQFIQAAAAAAAAAAAAAAAAAABOIA==");