furqansiddiqui / ethereum-rpc

Ethereum (geth) RPC client
MIT License
24 stars 32 forks source link

Transaction function #2

Closed anthonypaslange closed 6 years ago

anthonypaslange commented 6 years ago

Hello, I need an example on how to use the transaction function correctly. As I'm not only looking to send ethereum remotely but also erc20 tokens, I need to be able to use the data paramter, too.

furqansiddiqui commented 6 years ago

Ability to send ERC20 tokens from this package is completed and tests are passed too. If you want to try latest changes, you can get composer to update "dev-master", otherwise I will surely create new releases and post code sample here in morning.

Thank you for your patience

anthonypaslange commented 6 years ago

Thank you very much!

furqansiddiqui commented 6 years ago

I have created new releases on both repositories. Sync these new releases "0.1.1" on both.

Transferring ERC20 tokens in a nutshell:

$geth = new \EthereumRPC\EthereumRPC('127.0.0.1', 8545);
$erc20 = new \ERC20\ERC20($geth);

// Grab Token Instance
$token = $erc20->token("0x...CONTRACT-address");
// ERC20 Token Transfer Payee & Amount
$data = $token->encodedTransferData("0x...PAYEE-address", "1.12345");
// Prepare ETH transaction
$tx = $geth->personal()->transaction("0x...PAYER-address", "0x...CONTRACT-address")
    ->amount("0")
    ->data($data);

// Send Transaction
$txId = $tx->send("PASSWORD");

Although, I have covered this topic properly on my blog now as well, you can read here: https://www.furqansiddiqui.com/transfer-erc20-token-from-one-account-to-another-using-php/

Feel free to buzz me, reopen this or new issue if anything, I will be glad to help

zhawasolutions commented 3 years ago

I have created new releases on both repositories. Sync these new releases "0.1.1" on both.

Transferring ERC20 tokens in a nutshell:

$geth = new \EthereumRPC\EthereumRPC('127.0.0.1', 8545);
$erc20 = new \ERC20\ERC20($geth);

// Grab Token Instance
$token = $erc20->token("0x...CONTRACT-address");
// ERC20 Token Transfer Payee & Amount
$data = $token->encodedTransferData("0x...PAYEE-address", "1.12345");
// Prepare ETH transaction
$tx = $geth->personal()->transaction("0x...PAYER-address", "0x...CONTRACT-address")
    ->amount("0")
    ->data($data);

// Send Transaction
$txId = $tx->send("PASSWORD");

Although, I have covered this topic properly on my blog now as well, you can read here: https://www.furqansiddiqui.com/transfer-erc20-token-from-one-account-to-another-using-php/

Feel free to buzz me, reopen this or new issue if anything, I will be glad to help

How about to generate raw transaction ERC20 token with private key ? please help me sir to give sample script...