I'm trying to replicate a script that I have already running in nodejs in php.
On PHP I'm using "web3p/web3.php": "dev-master", "web3p/ethereum-tx": "^0.4.3" libraries.
When I send the signed transaction I'm always getting a "invalid sender" response. The transaction data is generated using 1inch.exchange API which works perfectly on nodejs.
I'm on PHP7.4 with GMP installed.
Here's a short version of my script
use Web3\Providers\HttpProvider;
use Web3\RequestManagers\HttpRequestManager;
use Web3p\EthereumTx\Transaction;
$web3 = new Web3(new HttpProvider(new HttpRequestManager($_ENV['API_MORALIS_BSC_URL'], 10)));
$eth = $web3->eth;
$params = [
"fromAddress" => $_ENV['ADDRESS_1'],
"fromTokenAddress" => $_ENV['COIN_1'],
"toTokenAddress" => $_ENV['COIN_2'],
"slippage" => 1,
"amount" => "10000000000000000",
];
$client = new \GuzzleHttp\Client(['http_errors' => false, 'timeout' => 10]);
$response = $client->get($_ENV['API_1INCH_BSC_URL']."swap", [ "query" => $params ]);
$transactionParams = json_decode($response->getBody()->getContents(),true)['tx'];
// TRANSACTION PARAMS
// Array
// (
// [from] => 0x3f9E320Fc------0DBA74d43c539a63bf
// [to] => 0x11111112------e05771c2dccff4faa26
// [data] => 0x7c025200000000000000000000000000baf90------0000000000000000000000000000000000000000000000000cfee7c08
// [value] => 0
// [gas] => 198325
// [gasPrice] => 15000000000
// [nonce] => 1d4
// [chainId] => 38
// )
$transaction = new Transaction($transactionParams);
$signedTransaction = '0x'.$transaction->sign($_ENV['PRIVATE_KEY_1']);
$eth->sendRawTransaction($signedTransaction, function ($err, $tx) { $err->getMessage(); });
I'd tried with and without including nonce, from and chainid on the transaction params.
I'm using a Moralis node, but the same happens with an Ankr node. Both nodes work fine when I run the nodejs version of the script.
I've been struggling whit this for a few days now, any help will be appreciated.
Thanks!