diff --git a/example/example.html b/example/example.html
index c4ea80b..6a76fbc 100644
--- a/example/example.html
+++ b/example/example.html
@@ -26,7 +26,7 @@
function claimToken() {
var email = Math.random() + "test@demo.io";
var url = "https://testnet.nebulas.io/claim/api/claim/"+ email+ "/"+ account.getAddressString() +"/";
- var request = new Neb.HttpRequest(url);
+ var request = new HttpRequest(url);
request.request("GET", "", "").then(function (resp) {
console.log(resp);
}).catch(function (err) {
diff --git a/lib/admin.js b/lib/admin.js
index 89b97d1..9a4b722 100644
--- a/lib/admin.js
+++ b/lib/admin.js
@@ -2,6 +2,7 @@
"use strict";
var utils = require('./utils/utils.js');
+var Transaction = require("./transaction.js");
/**
* Admin API constructor.
@@ -158,16 +159,7 @@ Admin.prototype.lockAccount = function (options) {
*/
Admin.prototype.sendTransaction = function (options) {
options = utils.argumentsToObject(['from', 'to', 'value', 'nonce', 'gasPrice', 'gasLimit', 'contract', 'binary'], arguments);
- var params = {
- "from": options.from,
- "to": options.to,
- "value": utils.toString(options.value),
- "nonce": options.nonce,
- "gasPrice": utils.toString(options.gasPrice),
- "gasLimit": utils.toString(options.gasLimit),
- "contract": options.contract,
- "binary": options.binary
- };
+ var params = new Transaction(options).toPlainObject();
return this._sendRequest("post", "/transaction", params);
};
@@ -228,16 +220,7 @@ Admin.prototype.signHash = function (options) {
*/
Admin.prototype.signTransactionWithPassphrase = function (options) {
options = utils.argumentsToObject(['from', 'to', 'value', 'nonce', 'gasPrice', 'gasLimit', 'contract', 'binary', 'passphrase'], arguments);
- var tx = {
- "from": options.from,
- "to": options.to,
- "value": utils.toString(options.value),
- "nonce": options.nonce,
- "gasPrice": utils.toString(options.gasPrice),
- "gasLimit": utils.toString(options.gasLimit),
- "contract": options.contract,
- "binary": options.binary
- };
+ var tx = new Transaction(options).toPlainObject();
var params = {
"transaction": tx,
"passphrase": options.passphrase
@@ -270,16 +253,7 @@ Admin.prototype.signTransactionWithPassphrase = function (options) {
*/
Admin.prototype.sendTransactionWithPassphrase = function (options) {
options = utils.argumentsToObject(['from', 'to', 'value', 'nonce', 'gasPrice', 'gasLimit', 'contract', 'binary', 'passphrase'], arguments);
- var tx = {
- "from": options.from,
- "to": options.to,
- "value": utils.toString(options.value),
- "nonce": options.nonce,
- "gasPrice": utils.toString(options.gasPrice),
- "gasLimit": utils.toString(options.gasLimit),
- "contract": options.contract,
- "binary": options.binary
- };
+ var tx = new Transaction(options).toPlainObject();
var params = {
"transaction": tx,
"passphrase": options.passphrase
diff --git a/lib/api.js b/lib/api.js
index 622c1c7..394866d 100644
--- a/lib/api.js
+++ b/lib/api.js
@@ -2,6 +2,7 @@
"use strict";
var utils = require('./utils/utils.js');
+var Transaction = require("./transaction.js");
/**
* User API constructor.
@@ -113,15 +114,7 @@ API.prototype.getAccountState = function (options) {
*/
API.prototype.call = function (options) {
options = utils.argumentsToObject(['from', 'to', 'value', 'nonce', 'gasPrice', 'gasLimit', 'contract'], arguments);
- var params = {
- "from": options.from,
- "to": options.to,
- "value": utils.toString(options.value),
- "nonce": options.nonce,
- "gasPrice": utils.toString(options.gasPrice),
- "gasLimit": utils.toString(options.gasLimit),
- "contract": options.contract
- };
+ var params = new Transaction(options).toPlainObject();
return this._sendRequest("post", "/call", params);
};
@@ -302,16 +295,7 @@ API.prototype.gasPrice = function () {
*/
API.prototype.estimateGas = function (options) {
options = utils.argumentsToObject(['from', 'to', 'value', 'nonce', 'gasPrice', 'gasLimit', 'contract', 'binary'], arguments);
- var params = {
- "from": options.from,
- "to": options.to,
- "value": utils.toString(options.value),
- "nonce": options.nonce,
- "gasPrice": utils.toString(options.gasPrice),
- "gasLimit": utils.toString(options.gasLimit),
- "contract": options.contract,
- "binary": options.binary
- };
+ var params = new Transaction(options).toPlainObject();
return this._sendRequest("post", "/estimateGas", params);
};
diff --git a/lib/transaction.js b/lib/transaction.js
index 7b11bf1..fecbfb2 100644
--- a/lib/transaction.js
+++ b/lib/transaction.js
@@ -262,10 +262,10 @@ Transaction.prototype = {
* gasLimit: 2000000
* });
* txData = tx.toPlainObject();
- * // {chainID: 1001, from: "n1USdDKeZXQYubA44W2ZVUdW1cjiJuqswxp", to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17", value: 1000000000000000000, nonce: 1, …}
+ * // {chainID: 1001, from: "n1USdDKeZXQYubA44W2ZVUdW1cjiJuqswxp", to: "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17", value: "1000000000000000000", nonce: 1, …}
*/
toPlainObject: function() {
- return {
+ var resObj = {
chainID: this.chainID,
from: this.from.getAddressString(),
to: this.to.getAddressString(),
@@ -275,6 +275,12 @@ Transaction.prototype = {
gasLimit: utils.isBigNumber(this.gasLimit) ? this.gasLimit.toNumber() : this.gasLimit,
contract: this.contract
};
+
+ resObj.value = utils.toString(resObj.value);
+ resObj.gasPrice = utils.toString(resObj.gasPrice);
+ resObj.gasLimit = utils.toString(resObj.gasLimit);
+
+ return resObj
},
/**
* Convert transaction to JSON string.