furqansiddiqui / erc20-php

Interact with Ethereum ERC20 Tokens
MIT License
164 stars 97 forks source link

Example to send the ERC20 transaction #40

Closed Eyad994 closed 1 year ago

Eyad994 commented 2 years ago

I have used this code but cannot transfer tokens from one account to another. Can you help me?

               $providerRPC = new GethRPC($eth,$provider);
               $eth = new \FurqanSiddiqui\Ethereum\Ethereum();
               $erc20 = new \FurqanSiddiqui\Ethereum\ERC20\ERC20($eth);
               $eth->contracts();
               $erc20->useRPCClient($providerRPC);
               $token = $erc20->token($contractAddress);
               $payer = $fromAccount;
               $payee = $toAccount;
               $amount = '3';
               $data = $token->encodedTransferData($eth->getAccount($payee), $amount);

              $tx = new \FurqanSiddiqui\Ethereum\Transactions\TxBuilder($eth);
             $transaction = $tx->gas(new \FurqanSiddiqui\Ethereum\Math\WEIValue('1'), 70000)
            ->to($eth->getAccount($payer))
            ->value(new \FurqanSiddiqui\Ethereum\Math\WEIValue('0'))
            ->data($data);
        dd($transaction);

This link doesn't work https://www.furqansiddiqui.com/transfer-erc20-token-from-one-account-to-another-using-php/