0

thanks all of guys help me. thanks very much. I created contract in rinkeby test network. the contract address is: https://rinkeby.etherscan.io/address/0x5dedcba9851e5c7ff464d5ee6ef75301a8c43d8b

I try to write code run contract transfrom method for move ERC2.0 token from A address to B address. but is always stop and show error message:Transaction has been reverted by the EVM. I am not sure what's trouble. hope someone help me.

fs = require("fs");
Web3 = require('web3');
url = "https://rinkeby.infura.io/v3/29129372289d49dca8ecec82d0aa8e7a";
web3 = new Web3(new Web3.providers.HttpProvider(url));
var contractAddress ="0x5DedCBa9851E5C7FF464D5Ee6Ef75301a8c43d8b";
var abiArray = JSON.parse(fs.readFileSync('kct.json', 'utf-8'));
abi = JSON.parse(abiArray.result);
var contract = new web3.eth.Contract(abi,contractAddress);

web3.eth.getBlock("latest",function(err,block){
const gasLimit = block.gasLimit;
console.log('gas limit:',gasLimit);
prkey="0xDE9EAD9D7DE97A3F94D66F9D8D7BF437AA76A28D4A13202B446D48AB1979DBDB";
data = contract.methods.transferFrom("0x410E6a1be27424091ABb15aA096D492958fD55f1","0xf17f52151EbEF6C7334FAD080c5704D77216b732","12").encodeABI();
console.log("data",data);

    console.log('gasPrice:',gasPrice);

    console.log("contractAddress",contractAddress);
    var tx = {
    from:"0x410E6a1be27424091ABb15aA096D492958fD55f1",
    to:contractAddress,
    data:data,
    gasPrice: web3.utils.toHex(4200000000),
    gasLimit: web3.utils.toHex(4300000),
    };
    web3.eth.accounts.signTransaction(tx,prkey).then(tx => {
            console.log('Result++: ', tx);
            var raw = tx.rawTransaction;
            web3.eth.sendSignedTransaction(raw).on('receipt', res => {
                    console.log('操作成功');
            }).on('error', err => {
                    console.log(err);
            });
    }).then(receipt => console.log("Transaction succeeded", receipt)).catch(error => console.error(error))
})
  • usually this kind of errors is not meeting revert , assert or require conditions, so you must check what input are you giving to your contract, and you should post the method's source code if you want someone to help you. – Nulik Sep 18 '18 at 17:42
  • you have 3 requires there in transfer() method, some of them fails, post also the transaction hash, so we can check what input did you send to the contract – Nulik Sep 18 '18 at 17:44
  • and the most likely, it is that you don't have the balance – Nulik Sep 18 '18 at 17:45
1

It looks like you're calling transferFrom(), which is a way for address A to transfer tokens from address B to address C. In order to do that, address B must first authorize address A to do that by calling approve().

But it looks like you're just trying to transfer from your own account, so you should just use transfer():

data = contract.methods.transfer("0xf17f52151EbEF6C7334FAD080c5704D77216b732", "12").encodeABI();
  • thanks smarx! it is run right. I need read more code, need know more about contract code. – Troublechain Sep 19 '18 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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