javascriptnode.jsethereumweb3jsether

How to send Ether from Address with private key and password?


I'm trying to use PHP and Cron to send Ether from an existing account using web3 or something similar, any tips on how I can accomplish this?

I have JSON in an SQL table {"address":"0x22b853A8Df90BF9A7e21445C16FBbEaa43e0c307","password":"inu8p","privateKey":"0xb9cabca09e5cbdfb2c953d574bce5b9d837a91ffe1f3817fc6a01da63bf5ff56"}

The problem is the JavaScript doesn't get executed with CRON. Is there any library in Node where I can send a POST request via an API or something?


Solution

  • You want to send a raw Ethereum transaction in PHP, so in your case I'd recommend php-eth-raw-tx package.

    The usage is pretty simple:

    $tx = new \EthereumRawTx\Transaction(
    \BitWasp\Buffertools\Buffer::hex('d44d259015b61a5fe5027221239d840d92583adb'),
    \BitWasp\Buffertools\Buffer::int(1 * 10**18),
    );
    
    $raw = $tx->getRaw(\BitWasp\Buffertools\Buffer::hex('b9cabca09e5cbdfb2c953d574bce5b9d837a91ffe1f3817fc6a01da63bf5ff56'));
    

    In this example you send 1.0 ETH from address 0x22b853A8Df90BF9A7e21445C16FBbEaa43e0c307 (identified by a private key 0xb9cabca09e5cbdfb2c953d574bce5b9d837a91ffe1f3817fc6a01da63bf5ff56) to address 0xd44d259015b61a5fe5027221239d840d92583adb.

    All you need to do is to create a PHP file and add it to your crontab.

    See more examples here: https://github.com/Domraider/php-eth-raw-tx/tree/master/examples