drlecks / Simple-Web3-Php

A web3 php interface for interacting with the Ethereum blockchain and ecosystem.
MIT License
70 stars 30 forks source link

Автовыввод #7

Closed webnatrix closed 2 years ago

webnatrix commented 2 years ago

Подскажите как сделать что бы с кошелька n перевести на комиссию и отправить с кошелька x на другой токены bep20

drlecks commented 2 years ago

Hi!

Sorry but I don't speak Russian and it looks like Google translate did a poor job. But I'll leave here some ideas I think I undestood.

BEP20 is just a Binance (BSC) extension of ERC20 , so all the standard should be available. To transfer tokens from one address to another, you simply have to use the SWeb3_Contract::send() function. There are some examples of send operations on the Example/example.send.php script.

The ERC20 contract has some singularities as tokens are owned by addresses. So a "signer" can only transfer tokens from him to another address (Yes, you can approve 3rd parties, but that's another chapter).

I'll publish a full example featuring most common interaction in ERC20 contracts at Example/example.erc20.php.

I hope this resolves your problems!

BTW, gitter may be more appropiate fot this type of questions: https://gitter.im/Simple-Web3-Php/community

webnatrix commented 2 years ago

Thanks, I sort of figured it out. Is it possible to make 1 transaction so that the commission is transferred from wallet 1 to wallet 2. And ERC20 is transferred from wallet 2?

drlecks commented 2 years ago

If I got your problem, you want to make a transaction where (for example) you send 2 BNB to a contract, and the contract gives back to the sender 2 tokens. Something like a pair-token?

What you ask for should be done in the contract logic (Solidity) in order to be done in just one transaction, and to make sure all the process is atomic. You can do that extending the regular ERC20 or making a contract that can interact with ERC20 contracts externally (that would be my choice). Then, you would only need to call your new function, as it's done in the example.erc20.php script.

In another repository I have a "sale" contract with similar features. Check buyTokens() there. Alert: It's a pretty old and outdated script and it's missing some basic features, but works as example.

This being said, If you are making a service, I would place all the actions triggered by the user on the client side (browser/javascript). So you don't need to hold, send nor receive any personal data like the private key.