There is solidity erc865 code
function transferFromPreSigned(
bytes _signature,
address _from,
address _to,
uint256 _value,
uint256 _fee,
uint256 _nonce
)
public
returns (bool)
{
require(_to != address(0));
require(signatures[_signature] == false);
bytes32 hashedTx = transferFromPreSignedHashing(address(this), _from, _to, _value, _fee, _nonce);
address spender = recover(hashedTx, _signature);
require(spender != address(0));
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][spender] = allowed[_from][spender].sub(_value);
balances[spender] = balances[spender].sub(_fee);
balances[msg.sender] = balances[msg.sender].add(_fee);
signatures[_signature] = true;
Transfer(_from, _to, _value);
Transfer(spender, msg.sender, _fee);
return true;
}
function transferFromPreSignedHashing(
address _token,
address _from,
address _to,
uint256 _value,
uint256 _fee,
uint256 _nonce
)
public
pure
returns (bytes32)
{
/* "b7656dc5": transferFromPreSignedHashing(address,address,address,uint256,uint256,uint256) */
return keccak256(bytes4(0xb7656dc5), _token, _from, _to, _value, _fee, _nonce);
}
I am executing smart contract code from script like that
// First Generate Sign
generateFromSign: function () {
const self = this
const from = "0xf731eC19279849312A163793d4E4a58878A21558";
const receiver = document.getElementById('receiver').value.toString()
const amount = parseInt(document.getElementById('amount').value)
const fee = parseInt(document.getElementById('fee').value)
const nonce = parseInt("12345")
let erc865
erc865Token.deployed().then(function (instance) {
erc865 = instance
console.log(erc865);
const token = erc865.address.toString()
return erc865.transferFromPreSignedHashing(token,from, receiver, amount, fee, nonce)
}).then(function (hash) {
web3.eth.sign(account, hash, function(error, signature) {
if (!error) {
console.log("Hash:"+hash);
console.log("Signature:"+signature);
self.setSign(signature)
} else {
console.log(error);
}
});
})
}
// Click the button to transfer "from" -> "receiver". Transaction must be executed by "account"
delegatedFromTransfer: function () {
const self = this
const from = "0xf731eC19279849312A163793d4E4a58878A21558";
const receiver = document.getElementById('receiver').value.toString()
const amount = parseInt(document.getElementById('amount').value)
const fee = parseInt(document.getElementById('fee').value)
const nonce = parseInt("12345")
const signature = document.getElementById('signature').value.toString()
this.setStatus('Initiating transaction... (please wait)')
let erc865
erc865Token.deployed().then(function (instance) {
erc865 = instance
console.log(erc865);
return erc865.transferFromPreSigned(signature,from, receiver,amount,fee,nonce, { from: account })
}).then(function () {
self.setStatus('Transaction complete!')
self.refreshBalance()
self.refreshEther()
}).catch(function (e) {
console.log(e)
self.setStatus('Error sending coin; see log.')
})
}
When call "delegatedFromTransfer" function from front end I am getting error from MetaMask. Error message : "ALERT: Transaction Error. Exception thrown in contract code."