From 6ba821fec15398c7999673eb122e0ce3b235e669 Mon Sep 17 00:00:00 2001 From: Nicholas Addison <> Date: Sun, 15 Oct 2017 23:24:49 +1100 Subject: [PATCH 1/7] removed privateKey from web3.eth.signTransaction and web3.eth.accounts.signTransaction documentation --- docs/web3-eth-accounts.rst | 17 +++++++++-------- docs/web3-eth.rst | 7 +++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/web3-eth-accounts.rst b/docs/web3-eth-accounts.rst index 7cfb5d67f38..a0dc1b422c8 100644 --- a/docs/web3-eth-accounts.rst +++ b/docs/web3-eth-accounts.rst @@ -145,9 +145,9 @@ signTransaction .. code-block:: javascript - web3.eth.accounts.signTransaction(tx, privateKey [, callback]); + web3.eth.accounts.signTransaction(tx [, callback]); -Signs an Ethereum transaction with a given private key. +Signs an Ethereum transaction with the accounts private key. ---------- Parameters @@ -161,8 +161,7 @@ Parameters - ``value`` - ``String``: (optional) The value of the transaction in wei. - ``gas`` - ``String``: The gas provided by the transaction. - ``gasPrice`` - ``String``: (optional) The gas price set by this transaction, if empty, it will use :ref:`web3.eth.gasPrice() ` -2. ``privateKey`` - ``String``: The private key to sign with. -3. ``callback`` - ``Function``: (optional) Optional callback, returns an error object as first parameter and the result as second. +2. ``callback`` - ``Function``: (optional) Optional callback, returns an error object as first parameter and the result as second. ------- @@ -184,11 +183,13 @@ Example .. code-block:: javascript - web3.eth.accounts.signTransaction({ + var account = web3.eth.accounts.privateKeyToAccount('0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'); + + account.signTransaction({ to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55', value: '1000000000', gas: 2000000 - }, '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318') + }) .then(console.log); > { messageHash: '0x88cfbd7e51c7a40540b233cf68b62ad1df3e92462f1c6018d6d67eae0f3b08f5', @@ -199,14 +200,14 @@ Example } // if nonce, chainId, gas and gasPrice is given it returns synchronous - web3.eth.accounts.signTransaction({ + account.signTransaction({ to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55', value: '1000000000', gas: 2000000, gasPrice: '234567897654321', nonce: 0, chainId: 1 - }, '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318') + }) > { messageHash: '0x6893a6ee8df79b0f5d64a180cd1ef35d030f3e296a5361cf04d02ce720d32ec5', r: '0x09ebb6ca057a0535d6186462bc0b465b561c94a295bdb0621fc19208ab149a9c', diff --git a/docs/web3-eth.rst b/docs/web3-eth.rst index f6219fc8e6f..64e6f3a4fd8 100644 --- a/docs/web3-eth.rst +++ b/docs/web3-eth.rst @@ -1167,9 +1167,9 @@ signTransaction .. code-block:: javascript - web3.eth.signTransaction(transactionObject, address [, callback]) + web3.eth.signTransaction(transactionObject [, callback]) -Signs a transaction. This account needs to be unlocked. +Signs a transaction using the transactionObject.from account on the remote Ethereum node. This account needs to be unlocked. ---------- Parameters @@ -1177,8 +1177,7 @@ Parameters 1. ``Object`` - The transaction data to sign :ref:`web3.eth.sendTransaction() ` for more. -2. ``String`` - Address to sign transaction with. -3. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. +2. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. ------- From 4ce9e6d76fc9881d3ed43f1b5670e996446d902d Mon Sep 17 00:00:00 2001 From: Nicholas Addison <> Date: Sun, 15 Oct 2017 23:24:49 +1100 Subject: [PATCH 2/7] removed privateKey from web3.eth.signTransaction and web3.eth.accounts.signTransaction documentation --- docs/web3-eth-accounts.rst | 17 +++++++++-------- docs/web3-eth.rst | 7 +++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/web3-eth-accounts.rst b/docs/web3-eth-accounts.rst index 7cfb5d67f38..a0dc1b422c8 100644 --- a/docs/web3-eth-accounts.rst +++ b/docs/web3-eth-accounts.rst @@ -145,9 +145,9 @@ signTransaction .. code-block:: javascript - web3.eth.accounts.signTransaction(tx, privateKey [, callback]); + web3.eth.accounts.signTransaction(tx [, callback]); -Signs an Ethereum transaction with a given private key. +Signs an Ethereum transaction with the accounts private key. ---------- Parameters @@ -161,8 +161,7 @@ Parameters - ``value`` - ``String``: (optional) The value of the transaction in wei. - ``gas`` - ``String``: The gas provided by the transaction. - ``gasPrice`` - ``String``: (optional) The gas price set by this transaction, if empty, it will use :ref:`web3.eth.gasPrice() ` -2. ``privateKey`` - ``String``: The private key to sign with. -3. ``callback`` - ``Function``: (optional) Optional callback, returns an error object as first parameter and the result as second. +2. ``callback`` - ``Function``: (optional) Optional callback, returns an error object as first parameter and the result as second. ------- @@ -184,11 +183,13 @@ Example .. code-block:: javascript - web3.eth.accounts.signTransaction({ + var account = web3.eth.accounts.privateKeyToAccount('0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'); + + account.signTransaction({ to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55', value: '1000000000', gas: 2000000 - }, '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318') + }) .then(console.log); > { messageHash: '0x88cfbd7e51c7a40540b233cf68b62ad1df3e92462f1c6018d6d67eae0f3b08f5', @@ -199,14 +200,14 @@ Example } // if nonce, chainId, gas and gasPrice is given it returns synchronous - web3.eth.accounts.signTransaction({ + account.signTransaction({ to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55', value: '1000000000', gas: 2000000, gasPrice: '234567897654321', nonce: 0, chainId: 1 - }, '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318') + }) > { messageHash: '0x6893a6ee8df79b0f5d64a180cd1ef35d030f3e296a5361cf04d02ce720d32ec5', r: '0x09ebb6ca057a0535d6186462bc0b465b561c94a295bdb0621fc19208ab149a9c', diff --git a/docs/web3-eth.rst b/docs/web3-eth.rst index f6219fc8e6f..64e6f3a4fd8 100644 --- a/docs/web3-eth.rst +++ b/docs/web3-eth.rst @@ -1167,9 +1167,9 @@ signTransaction .. code-block:: javascript - web3.eth.signTransaction(transactionObject, address [, callback]) + web3.eth.signTransaction(transactionObject [, callback]) -Signs a transaction. This account needs to be unlocked. +Signs a transaction using the transactionObject.from account on the remote Ethereum node. This account needs to be unlocked. ---------- Parameters @@ -1177,8 +1177,7 @@ Parameters 1. ``Object`` - The transaction data to sign :ref:`web3.eth.sendTransaction() ` for more. -2. ``String`` - Address to sign transaction with. -3. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. +2. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. ------- From 21ddda02b5bac390f32eb854724120d4ca8ded94 Mon Sep 17 00:00:00 2001 From: Nicholas Addison <> Date: Mon, 16 Oct 2017 00:45:07 +1100 Subject: [PATCH 3/7] added vscode to gitignore and minor doco change --- .gitignore | 1 + docs/web3-eth-accounts.rst | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7ab4350d86a..2dfb2150de0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ bower_components /bower .idea/ .npm/ +.vscode/ \ No newline at end of file diff --git a/docs/web3-eth-accounts.rst b/docs/web3-eth-accounts.rst index a0dc1b422c8..acc8686d50d 100644 --- a/docs/web3-eth-accounts.rst +++ b/docs/web3-eth-accounts.rst @@ -147,7 +147,7 @@ signTransaction web3.eth.accounts.signTransaction(tx [, callback]); -Signs an Ethereum transaction with the accounts private key. +Signs an Ethereum transaction with the account's private key. ---------- Parameters From 8a266a547e15a0d8c440a42cd21dea3b3c5b36a3 Mon Sep 17 00:00:00 2001 From: Nicholas Addison <> Date: Mon, 16 Oct 2017 09:35:18 +1100 Subject: [PATCH 4/7] Added test to show privateKey can not be passed to accounts.signTransaction --- test/eth.accounts.signTransaction.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/eth.accounts.signTransaction.js b/test/eth.accounts.signTransaction.js index c4c15708178..ae88ce5290a 100644 --- a/test/eth.accounts.signTransaction.js +++ b/test/eth.accounts.signTransaction.js @@ -63,6 +63,18 @@ describe("eth", function () { }); }); + it("signTransaction using passed private key", function() + { + var ethAccounts = new Accounts(); + + var testAccount = ethAccounts.privateKeyToAccount(tests[0].privateKey); + assert.equal(testAccount.address, tests[0].address); + + var tx = testAccount.signTransaction(test.transaction, tests[1].privateKey); + + assert.equal(tx.rawTransaction, tests[1].rawTransaction); + }); + tests.forEach(function (test, i) { it("signTransaction using the iban as \"to\" must compare to eth_signTransaction", function() { var ethAccounts = new Accounts(); From 3752fb2396f1e36b61b218074f7dc2ea4065c93b Mon Sep 17 00:00:00 2001 From: Nicholas Addison <> Date: Thu, 19 Oct 2017 23:13:24 +1100 Subject: [PATCH 5/7] removed passing of private key --- test/eth.accounts.signTransaction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/eth.accounts.signTransaction.js b/test/eth.accounts.signTransaction.js index ae88ce5290a..fdd3db25bc3 100644 --- a/test/eth.accounts.signTransaction.js +++ b/test/eth.accounts.signTransaction.js @@ -70,7 +70,7 @@ describe("eth", function () { var testAccount = ethAccounts.privateKeyToAccount(tests[0].privateKey); assert.equal(testAccount.address, tests[0].address); - var tx = testAccount.signTransaction(test.transaction, tests[1].privateKey); + var tx = testAccount.signTransaction(test.transaction); assert.equal(tx.rawTransaction, tests[1].rawTransaction); }); From 630586695eb1a43ad852d83fbdb726b8f937d5f7 Mon Sep 17 00:00:00 2001 From: Nicholas Addison <> Date: Sun, 22 Oct 2017 01:00:21 +1100 Subject: [PATCH 6/7] Added Eth.signTransaction function renamed accounts.privateToAccount to accounts.privateKeyToAccount Added missing Contract.options Added status to TransactionReceipt --- packages/web3/index.d.ts | 2 +- packages/web3/types.d.ts | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/web3/index.d.ts b/packages/web3/index.d.ts index e0799833411..c8e825c62b0 100644 --- a/packages/web3/index.d.ts +++ b/packages/web3/index.d.ts @@ -10,7 +10,7 @@ declare class Web3 { Shh: new (provider: t.Provider) => t.Shh Bzz: new (provider: t.Provider) => t.Bzz } - constructor(provider: t.Provider) + constructor(provider: t.Provider | string) version: string BatchRequest: new () => t.BatchRequest extend(methods: any): any // TODO diff --git a/packages/web3/types.d.ts b/packages/web3/types.d.ts index 1e71cfeedae..a11dc79ade5 100644 --- a/packages/web3/types.d.ts +++ b/packages/web3/types.d.ts @@ -112,6 +112,22 @@ export declare interface TransactionReceipt { logs?: Array events?: { [eventName: string]: EventLog + }, + status: string +} +export declare interface EncodedTransaction { + raw: string, + tx: { + nonce: string, + gasPrice: string, + gas: string, + to: string, + value: string, + input: string, + v: string, + r: string, + s: string, + hash: string } } export declare interface BlockHeader { @@ -265,6 +281,10 @@ export declare interface Contract { options: { address: string jsonInterface: ABIDefinition[] + data: string + from: string + gasPrice: string + gas: number } methods: { [fnName: string]: (...args) => TransactionObject @@ -313,7 +333,7 @@ export declare class Eth { } accounts: { 'new'(entropy?: string): Account - privateToAccount(privKey: string): Account + privateKeyToAccount(privKey: string): Account publicToAddress(key: string): string signTransaction(tx: Tx, privateKey: string, returnSignature?: boolean, cb?: (err: Error, result: string | Signature) => void): Promise | Signature recoverTransaction(signature: string | Signature): string @@ -376,6 +396,7 @@ export declare class Eth { isSyncing(cb?: Callback): Promise net: Net personal: Personal + signTransaction(tx: Tx, address?: string, cb?: Callback): Promise sendSignedTransaction(data: string, cb?: Callback): PromiEvent sendTransaction(tx: Tx, cb?: Callback): PromiEvent submitWork(nonce: string, powHash: string, digest: string, cb?: Callback): Promise From 3daf969e1a906c1bfe5aa70794f1b2adc3d965cd Mon Sep 17 00:00:00 2001 From: Nicholas Addison Date: Sun, 22 Oct 2017 08:20:27 +1100 Subject: [PATCH 7/7] reversing changes so my forked 1.0 branch is in sync with the upstream 1.0 branch --- docs/web3-eth-accounts.rst | 17 ++++++++--------- docs/web3-eth.rst | 7 ++++--- test/eth.accounts.signTransaction.js | 12 ------------ 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/docs/web3-eth-accounts.rst b/docs/web3-eth-accounts.rst index 8e0fac08898..77ce087365a 100644 --- a/docs/web3-eth-accounts.rst +++ b/docs/web3-eth-accounts.rst @@ -146,9 +146,9 @@ signTransaction .. code-block:: javascript - web3.eth.accounts.signTransaction(tx [, callback]); + web3.eth.accounts.signTransaction(tx, privateKey [, callback]); -Signs an Ethereum transaction with the accounts private key. +Signs an Ethereum transaction with a given private key. ---------- Parameters @@ -162,7 +162,8 @@ Parameters - ``value`` - ``String``: (optional) The value of the transaction in wei. - ``gas`` - ``String``: The gas provided by the transaction. - ``gasPrice`` - ``String``: (optional) The gas price set by this transaction, if empty, it will use :ref:`web3.eth.gasPrice() ` -2. ``callback`` - ``Function``: (optional) Optional callback, returns an error object as first parameter and the result as second. +2. ``privateKey`` - ``String``: The private key to sign with. +3. ``callback`` - ``Function``: (optional) Optional callback, returns an error object as first parameter and the result as second. ------- @@ -184,13 +185,11 @@ Example .. code-block:: javascript - var account = web3.eth.accounts.privateKeyToAccount('0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'); - - account.signTransaction({ + web3.eth.accounts.signTransaction({ to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55', value: '1000000000', gas: 2000000 - }) + }, '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318') .then(console.log); > { messageHash: '0x88cfbd7e51c7a40540b233cf68b62ad1df3e92462f1c6018d6d67eae0f3b08f5', @@ -201,14 +200,14 @@ Example } // if nonce, chainId, gas and gasPrice is given it returns synchronous - account.signTransaction({ + web3.eth.accounts.signTransaction({ to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55', value: '1000000000', gas: 2000000, gasPrice: '234567897654321', nonce: 0, chainId: 1 - }) + }, '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318') > { messageHash: '0x6893a6ee8df79b0f5d64a180cd1ef35d030f3e296a5361cf04d02ce720d32ec5', r: '0x09ebb6ca057a0535d6186462bc0b465b561c94a295bdb0621fc19208ab149a9c', diff --git a/docs/web3-eth.rst b/docs/web3-eth.rst index 64e6f3a4fd8..f6219fc8e6f 100644 --- a/docs/web3-eth.rst +++ b/docs/web3-eth.rst @@ -1167,9 +1167,9 @@ signTransaction .. code-block:: javascript - web3.eth.signTransaction(transactionObject [, callback]) + web3.eth.signTransaction(transactionObject, address [, callback]) -Signs a transaction using the transactionObject.from account on the remote Ethereum node. This account needs to be unlocked. +Signs a transaction. This account needs to be unlocked. ---------- Parameters @@ -1177,7 +1177,8 @@ Parameters 1. ``Object`` - The transaction data to sign :ref:`web3.eth.sendTransaction() ` for more. -2. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. +2. ``String`` - Address to sign transaction with. +3. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. ------- diff --git a/test/eth.accounts.signTransaction.js b/test/eth.accounts.signTransaction.js index b8e89536374..1f99b317a0d 100644 --- a/test/eth.accounts.signTransaction.js +++ b/test/eth.accounts.signTransaction.js @@ -63,18 +63,6 @@ describe("eth", function () { }); }); - it("signTransaction using passed private key", function() - { - var ethAccounts = new Accounts(); - - var testAccount = ethAccounts.privateKeyToAccount(tests[0].privateKey); - assert.equal(testAccount.address, tests[0].address); - - var tx = testAccount.signTransaction(test.transaction); - - assert.equal(tx.rawTransaction, tests[1].rawTransaction); - }); - tests.forEach(function (test, i) { it("signTransaction using the iban as \"to\" must compare to eth_signTransaction", function() { var ethAccounts = new Accounts();