Jump to content

mrpmorris

New Members
  • Posts

    1
  • Joined

  • Last visited

mrpmorris's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi all I have the following code. require 'vendor/autoload.php'; use Web3\Web3; use Web3p\EthereumTx\EIP1559Transaction; $web3 = new Web3('https://eth-rinkeby.alchemyapi.io/v2/--api--'); $fromAddress = '0xB5A2FD09ed2Eb7AA3bBf55C7f8e8D8576B68b0F2'; $toAddress = '0x2928C5Fb489BE1182B3569a3863F1C61Cafde240'; $prvKey = '--private-key--'; $transactionAmount = 145; $gasLimit = 0; $baseFeePerGas = 0; $gasUsed = 0; $maxFeePerGas = 0; $estimatedGas = 0; $web3->eth->getBlockByNumber('pending',false,function($err,$success){ if ($err !== null) { echo 'Error: ' . $err->getMessage(); exit; } global $gasLimit; global $baseFeePerGas; global $gasUsed; $gasLimit = $success->gasLimit; $baseFeePerGas = $success->baseFeePerGas; $gasUsed = $success->gasUsed; }); $estimateGasRequest = [ 'from' => $fromAddress, 'to' => $toAddress, 'value' => $transactionAmount ]; $web3->eth->estimateGas($estimateGasRequest,function($err,$success){ if ($err !== null) { echo 'Error: ' . $err->getMessage(); exit; } global $estimatedGas; $estimatedGas = $success->value; }); echo $gasLimit; // Outputs 0x1c8debe echo '<br/>'; echo $baseFeePerGas; // Outputs 0x8 echo '<br/>'; echo $gasUsed; // Outputs 0x1c8bb1d echo '<br/>'; echo $estimatedGas; // Outputs 21000 echo '<br/>'; I am struggling to understand how I can use the retrieved values in order to fill out the required values for a transaction. Can someone help me to understand how I can calculate the values marked ?????? in the source code shown? $gweiFactor = 1 / 1000000000; $nonce = '113'; // generate transaction instance with transaction parameters $transactionInfo = [ 'gas' => ??????, 'maxPriorityFeePerGas' => ??????, 'maxFeePerGas' => ??????, 'nonce' => '0x' . dechex($nonce), 'from' => $fromAddress, 'to' => $toAddress, 'value' => '0x' . dechex($transactionAmount), 'chainId' => 4, // required 'accessList' => [], 'data' => '' ]); I tried with some hard-coded values that eth-rinkeby.alchemyapi.io seemed to accept (and give me a transaction hash) but the transaction never appears on the test net or actually transfers any eth. Can anyone help?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.