Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signTransaction gives 'Must provide "signTransaction" fn in constructor option' error #1599

Closed
ArvsIndrarys opened this issue Apr 30, 2018 · 8 comments
Assignees
Labels

Comments

@ArvsIndrarys
Copy link

For my project, I need to do some offline transaction signing, before sending the result to the backend, which will send them. But I am encountering the following error :

Error: Error: ProviderEngine - HookedWalletSubprovider - Must provide "signTransaction" fn in constructor options
    at HookedWalletSubprovider.signTransaction (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:18092)
    at t (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:486)
    at u (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:486)
    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:456
    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:18092
    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:459
...

I currently have :

> web3.version
{api: "0.20.3", getNode: ƒ, getNetwork: ƒ, …}

And I saw it in : https://github.com/ethereum/web3.js/blob/6d3e61a010501011a107a79574cc7516900fa9e4/lib/web3/methods/eth.js#L205
and (outdated) : https://web3js.readthedocs.io/en/1.0/web3-eth.html#signtransaction

I am clueless about how to resolve it as it don't seem to be due to my code... Can somebody help?

@ArvsIndrarys
Copy link
Author

I am using Metamask, which use Infura, for testing my app, so I am almost sure it isn't an ethereum client problem.

@jetpack3331
Copy link

jetpack3331 commented May 4, 2018

@ArvsIndrarys I have signTransaction implemented like this:

signTransaction: async (txParams, cb) => {
// Fetch private key as u want
const res = await wallets.fetchPrivateKey(txParams.from);
const privateKey = typeof res.result !== 'undefined' ? res.result : res;
const gasPrice = await web3.eth.getGasPrice();

const txObject = {
  from: txParams.from,
  to: txParams.to,
  data: txParams.data,
  gasPrice: web3.utils.toHex(gasPrice),
  gasLimit: web3.utils.toHex(gasLimit),
  value: '0x00',
  nonce: txParams.nonce,
  chainId: <NETWORKID>, // see: https://ethereum.stackexchange.com/questions/17051/how-to-select-a-network-id-or-is-there-a-list-of-network-ids
};

const tx = new Tx(txObject);
tx.sign(Buffer.from(privateKey, 'hex'));
try {
  const serialized = tx.serialize();
  cb(null, `0x${serialized.toString('hex')}`);
} catch (error) {
  console.log({ error });
}

}

@ArvsIndrarys
Copy link
Author

As my code would be expected to go to production and of public use, I won't accept extracting the private key because of security breach.
This method would extract and use Metamask under the hood without giving access to this key.

@jetpack3331
Copy link

@ArvsIndrarys of course, but if you can't use MetaMask or Ledger or something and u have your own methods tosigning, there is probably no other way. Ofc better is to have it on API hidden from browser

@ArvsIndrarys
Copy link
Author

Any other methods require private key extraction, so I had to use the sendTransaction() method.
I would have appreciated signing from the front-end and execute the transaction from my backend (web3J).

It seems I finally did it few days ago, using a little reverse-engineering and the sign() method, giving the transaction then extracting the r,s and v parameters ( https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsign ) and computing the result so as it looked like the signed Transaction given in the https://web3js.readthedocs.io/en/1.0/web3-eth.html#signtransaction example.

But as web3js and web3J don't sign the same way ( hyperledger/web3j#208 ) and I was never able to send the signed transaction from the backend :/ .
And from the logging, I couldn't determined if it was because my way was not working, or if it was due to the signing differences.

May I ask why the signTransaction() method was abandoned ?

@jetpack3331
Copy link

@ArvsIndrarys It wasnt abandoned.
https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsign is documentation for 0.2x.x

In version 1.0.0 there is signTransaction method

@ArvsIndrarys
Copy link
Author

My bad, I don't know know about my first problem then... Must provide "signTransaction" fn in constructor options is obscure to me

@nivida nivida added the 0.x.x label Aug 10, 2018
@nivida nivida self-assigned this Aug 10, 2018
@nivida
Copy link
Contributor

nivida commented Mar 25, 2019

Version 0.20.x got his last maintenance release with v0.20.7. Please update your code to the latest 1.0 version of Web3.js. Further details about the current project state are explained in the release announcement of version 1.0.0-beta.38.

@nivida nivida closed this as completed Mar 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants