1

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."

  • Is this the best indentation that you could come up with? – goodvibration Dec 19 '18 at 13:11
  • should I improve my question ? – Nizomjon Hajiev Dec 19 '18 at 13:13
0

I have quickly gathered the places in your contract which are likely to throw an exception (as reported to you by MetaMask). You should examine each one of them carefully in order to determine which one is causing the problem, and then fix your input accordingly. Note that there can be more than a single point of failure here:

// make sure that the destination account is not 0
require(_to != address(0));

// make sure that the signature is false
require(signatures[_signature] == false);

// make sure that the spender account is not 0
require(spender != address(0));

// make sure that the source account's balance is high enough
balances[_from] = balances[_from].sub(_value);

// make sure that the spender account's allowance is high enough
allowed[_from][spender] = allowed[_from][spender].sub(_value);

// make sure that the spender account's balance is high enough
balances[spender] = balances[spender].sub(_fee);

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.