lessmore92 / php-erc20

The simple way to interact with Ethereum ERC20 token.
MIT License
26 stars 26 forks source link

How to make a transfer without a specific token #3

Closed nathanielajayi7 closed 3 years ago

nathanielajayi7 commented 3 years ago

Is it possible to use this library to initialize a transaction in ETH without passing a specific token or contract address?

lessmore92 commented 3 years ago

Do you means, you want transfer ETH?

nathanielajayi7 commented 3 years ago

Yes. That's what I mean specifically

nathanielajayi7 commented 3 years ago

And how do I know a transaction was successful?

lessmore92 commented 3 years ago

Yes, you can use TransactionBuilder class.

Sample usage:

use Lessmore92\Ethereum\Foundation\Transaction\TransactionBuilder;
use Lessmore92\Ethereum\Token;

$nonce    = '04';
$gasPrice = '03f5476a00';
$gasLimit = '027f4b';
$to       = '1a8c8adfbe1c59e8b58cc0d515f07b7225f51c72';
$value    = '2a45907d1bef7c00';

$privateKey = 'b2f2698dd7343fa5afc96626dee139cb92e58e5d04e855f4c712727bf198e898';

$for_web3_client = new Token("", "https://mainnet.infura.io/v3/API_KEY");
$tx              = (new TransactionBuilder())
    ->setEth($for_web3_client->getEth())
    ->to($to)
    ->nonce($nonce)
    ->gasPrice($gasPrice)
    ->gasLimit($gasLimit)
    ->data('')
    ->amount($value)
    ->build()
;

//to get signed tx hash
echo $tx->sign($privateKey)
        ->getSignedHash()
;

//to send signed tx hash
$tx->sign($privateKey)
        ->send()
;

After call send method $tx->sign($privateKey)->send() if tx_id returns that means transaction was successful.

nathanielajayi7 commented 3 years ago

To be sure, all variables are hexadecimal?

lessmore92 commented 3 years ago

yes