10

Assuming I have deployed my ERC20 token, and the supply has been dispersed, is there any method of creating a separate contract that accepts that ERC20 token as payment and has user fields that send particular information to the contract?

Kind of like a contract that takes the token along with some information.

7

If you want to receive ERC20 tokens onto a new contract along with data, you can create the new contract using ERC 223 token standard. Read here (Dont be confused about the nomenclature, its ERC223 and not ERC23)

When you transfer the tokens, you can also send data in the function

transfer(address to, uint value, bytes data)

And since ERC223 is backward compatible with ERC20, there will be no breaking in contract.

A sample function can be as

function transferToContract(address _to, uint _value, bytes _data) private returns (bool success) {
    if (balanceOf(msg.sender) < _value) throw;
    balances[msg.sender] = safeSub(balanceOf(msg.sender), _value);
    balances[_to] = safeAdd(balanceOf(_to), _value);
    ContractReceiver reciever = ContractReceiver(_to);
    reciever.tokenFallback(msg.sender, _value, _data);
    Transfer(msg.sender, _to, _value, _data);
    StateChanged(true,"Transfer to contract successful");
    return true;
}
1

Here's 3 approaches you could use:

  1. In your first contract (contract A), you could add code that upon a transfer to an approved contract (B), you could make a delegate call to contract (B) to do something, and you could pass any information you have from contract A.

  2. You could make a dApp that listens for the Transfer event on contract A, and then makes a transaction request to contract B to do something.

  3. You could do similar to #2 except listen for the Approved event on A and then call the transfer on A yourself to ensure you transfer the token(s) to any address you want and also make a call to B to do whatever functionality you want there also.

0

I do not know.

I've tried answering similar question on the similar site: https://delegatecall.com/questions/smart-contract-accepting-tokens-instead-of-ether-as-payment-4ca5abce-0037-4bd6-a1ae-26ef1658bd0e#i-was-thinking-about-accepting-dai-stablecoin-pegged-to-1-but-i--b8087a40-5a59-4f7a-a1a5-a7c7d1048b86

What I would do (six months ago couldn't deploy my own ERC20 or ICO) is to legacy web application running web3.js and listeting to Transfer event (part of ERC20 standard) and triggering some action in the desired smart contract...

  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review – shane Nov 12 '18 at 18:49
  • Suggested an alternative. It does provide answer to the question. "Accepting an ERC20 Token as Payment" - or actually... Yeah, I should read the body of the question. – Mars Robertson Nov 13 '18 at 10:08

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.