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.
solidity
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));
}
Blockquote
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) {
console.log(hash);
console.log(signature);
} else {
console.log(error);
}
});
} else {
console.log(error);
}
});
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?