Can I transfer tokens from an ERC20 contract using PHP?

落爺英雄遲暮 提交于 2019-12-08 10:56:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!