This question already has an answer here:

I am using infura and web3 0.20.0 in back-end.(nodejs, I don't want to interact with metamask(front-end)) Now, I am facing a problem. I tried to use ERC865.


  function recoverPreSignedHash(
    address _token,
    bytes4 _functionSig,
    address _spender,
    uint256 _value,
    uint256 _fee,
    uint256 _nonce
  public pure returns (bytes32)
    //return keccak256(_token, _functionSig, _spender, _value, _fee, _nonce);
    return keccak256(abi.encodePacked(_token, _functionSig, _spender, _value, _fee, _nonce));


var Tx = require('ethereumjs-tx');
var Web3 = require('web3');
const testnet = 'https://ropsten.infura.io/';
const web3 = new Web3(new Web3.providers.HttpProvider(testnet));
var contractAddress = '0xf21BF631C...';
var contractABI = [{"constant":true,"inputs":[],"................}]
var contract = web3.eth.contract(contractABI).at(contractAddress);
var transferSig = "0x48664c16";
var to = "0x36C906644FEbA405...";
var val = 100*Math.pow(10, 18);
var fee = 20*Math.pow(10, 18);
var nonce =web3.eth.getTransactionCount("0xD0A8800973cb...");
contract.recoverPreSignedHash(contractAddress, transferSig, to, val, fee, nonce, function(error, hash) {
    if (!error) {
        web3.eth.sign("0xD0A8800973cbEF2639Eb...", hash, function(error, signature) {
        if (!error) {
        } else {
    } else {

But it returns"Error: The method eth_sign does not exist/is not available" Because Infura does not have private key, so it doesn't have sign method. This problem is as same as sendTransaction so I use sendRawTransaction. How do I solve "sign" problem? (nodejs & web 0.20.0) How do I sign this hash Manually?(I have private key) What is "web3.eth.sign()" machanism?

marked as duplicate by Ismael, Richard Horrocks, flygoing, Achala Dissanayake, shane May 10 at 15:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I can give you a code for signing manually yourself, but it's compatible with web3 v1 (beta34), so you'll need to upgrade your version. – goodvibration May 7 at 13:40
  • OK, Thanks a lot. Can u email me at "yesggdd@gmail.com" ? thank you. – user53449 May 7 at 16:01
  • No, the point is to post the answers here! – goodvibration May 7 at 16:02
  • Side note: Things like 100*Math.pow(10, 18) are prone to errors in Javascript, because Number.MAX_SAFE_INTEGER is a much smaller value (2^53-1 to be accurate). You should use BigNumber in such cases. – goodvibration May 7 at 16:05
  • I think I don't need to send transaction. Just signature problem. – user53449 May 8 at 5:44