1

I have a smart contract on Ropsten that I'm testing: 0x813870feba76f27ec1AfcF79432e065A4839F7AB

Transaction has failed(reverted).

What is the problem, because I don't see an error message

Transaction on Etherscan: https://ropsten.etherscan.io/tx/0x94f838aaa201af26818a339a8deb50e0a6e45678316a423ad0c238075d2470e1

2
  • looks like the function you call invokes 'transferFrom' on an ERC20 token. Did you approve the transfer beforehand with another transaction? Jan 14, 2020 at 0:22
  • no i havent, how would i do that?
    – yappy twan
    Jan 14, 2020 at 0:24

2 Answers 2

1

A @Chan-Ho says, there is a transferFrom() in the buy function, and you said you didn't approve() first, so that is the first problem.

This looks like the Token contract - AGI:

erc20 = TOKEN(address(0x8eb24319393716668d768dcec29356ae9cffe285));

You have to call the approve() function there to "authorize" the snet contract to pull some tokens from your account.

You'll see buy is going to pull amount (the first argument in your transaction, you set to 1). So snet needs an "allowance" of one or more. You sent that value by sending an approve(args, ...) to the token contract.

Have a look here for details: https://eips.ethereum.org/EIPS/eip-20

The "spender" will be the snet contract where you sent the failed transaction. In summary, it's a two-step process.

Here's the code we're looking at. You're transaction set data there. https://ropsten.etherscan.io/address/0x8eb24319393716668d768dcec29356ae9cffe285#code

Hope it helps.

13
  • ok i get that but where do i call teh approve function? do i call it from the Ui, because i dont see teh approve function in my smart contract
    – yappy twan
    Jan 14, 2020 at 0:42
  • There are lots of ways and we don't know if you used a UI, command line, MyEtherWallet, something else. I'll give you a tip if you give us a hint. Jan 14, 2020 at 1:01
  • i used metamask
    – yappy twan
    Jan 14, 2020 at 7:44
  • There must something else. From your comment on the other answer, I'm guessing you didn't use Remix to form the transaction for buy. In any case, MetaMask is fine for signing and your task is to send approve(<snet_address", 1) TO the AGI contract. If should be FROM the same account you plan to use to try buy again. Jan 14, 2020 at 8:03
  • what are you saying dude?
    – yappy twan
    Jan 14, 2020 at 8:06
0

Ok, I see @rob-hitchens-b9lab has answered the question beautifully while I was busy ;), so I'll give a short, cookbook answer of the steps

I don't know what you're using but most people are familiar with Remix, so here are the steps in Remix:

  1. In the "Solidity Compiler" tab, create and compile an Erc20token.sol file :
interface Erc20Token {
   function totalSupply() external view returns (uint256);
   function balanceOf(address account) external view returns (uint256);
   function transfer(address recipient, uint256 amount) external returns (bool);
   function allowance(address owner, address spender) external view returns (uint256);
   function approve(address spender, uint256 amount) external returns (bool);
   function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}
  1. In the "Deploy and Run Transactions" tab, use the token address 0x8eb24319393716668d768dcec29356ae9cffe285 from the snet contract (your contract), with the "At Address" option instead of "Deploy":

enter image description here

  1. From the same tab, use the "approve" method of the contract. I used amount equal to 1. The approved address should be the snet contract, 0x813870feba76f27ec1AfcF79432e065A4839F7AB. (Here's the approve transaction on Etherscan.)

  2. Now go through similar steps as above to get your sns contract to appear in the "deployed contracts" section. Use your snet contract's "buy" method, as you did before, making sure amount is at most the amount approved in step 3.

As you can see from Etherscan, I used some of my precious test Ether to do the steps above, so your contract will show a transaction from one of my dev accounts :) .

After doing all the above, I realized although I approved a token transfer, I don't actually have any of your tokens, so the final "buy" transaction would fail when trying to do the transfer. I'm pretty confident it would work otherwise though.

34
  • makes absolutley no sense to do it like that
    – yappy twan
    Jan 14, 2020 at 7:45
  • It does, actually. Jan 14, 2020 at 8:01
  • i dont like to do it that way, nobody is doing it that complicated, i appreciate your help but its not a help cause its a weird way of doing it
    – yappy twan
    Jan 14, 2020 at 8:03
  • and none of your transactions went through, so what good is this doing?
    – yappy twan
    Jan 14, 2020 at 8:04
  • 1
    oki finally got it to work, thanks for your patience guys
    – yappy twan
    Jan 14, 2020 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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