Currently I setup on my website the ability to accept my ERC20 as payment. In order to do this, I am using a plugin from wordpress that will complete this task using two steps.

  1. Depositing the checkout amount into a smart contract that the creator of the plugin built.

  2. Then somehow, interacting with my token contract to approve the amount and approve itself to complete the transaction.

This all requires two transactions on the Ethereum blockchain. My question is, I never approved the plugin's smart contract, so how is it able to do this? Can't anyone create a smart contract to trick a token contract and drain funds from any account?


The intermediary contract can interact with your contract but can not extract funds if there is not a function for that. There is of course the issues with reentrancy and other patterns that can be avoided with a good design.

However in the standard ERC20 these issues are covered, so using functions in your contract doesn't put you on risk.

Now, you should be able to see the code of the intermediary contract because if it takes in your behave the tokens from your users you need to be sure that it will at the end send the tokens to you.

Furthermore, you can add JavaScript code using web3 to your page to accept payment in tokens without the intermediary. This will be cheaper for your users and safer for you. The users will need to use metamask though.

How this helps

  • Thanks again Jaime. You've helped a lot. I've tested it and it works fine, but I'd be more comfortable with having complete control over the process myself. I don't want to put my customers or holders of the token at risk so I'll explore the JavaScript using web3 method you mentioned. Before I start researching, do you have any direct links to a sample of this implementation and its code? Thanks again! – shyheim103 May 27 '18 at 19:42
  • I can share a sample code to get you started. Starting a new question will be easy or if you want I can send it to you, but a new question is better because other people will be able to judge if what I am suggesting is optimal or not. Let me know. – Jaime May 28 '18 at 5:38

On an ERC20 token implementation, the transferFrom() function has relation with this ones:

allowance(address *_owner*, address *_spender*) constant returns (uint256 remaining)

This function combined with:

approve(address _spender, uint256 _value) returns (bool success)

And a good implementation of public and private attributes and a rationale overriding of these methods will make the work.

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.