问题
I'm developing a website using Web3 with Metamask, users can purchase tokens by sending ETH to an address. What I want to have done is that after the ETH is received it sends the tokens to the users ETH address automatically with backend code.
The actual contract code
Sending is not working unless the account is on Metamask
Any tips on how I can get it to send the tokens through the backend by specifying the private key of an address with tokens?
Thanks for your help.
回答1:
Yes, you can, I have written a ERC20 library for PHP.
https://www.furqansiddiqui.com/libraries/erc20-php/
https://github.com/furqansiddiqui/erc20-php
To send ERC20 tokens to an address, all you need to do is use "encodedTransferData" method and use the returning string as value for "data" param when you send Ethereum transaction.
There are other ERC20 standard methods included as well, such as name(), balanceOf(), decimals(), symbol()
来源:https://stackoverflow.com/questions/48460161/can-i-transfer-tokens-from-an-erc20-contract-using-php