我正在尝试复制我已经在php中的nodejs中运行的脚本。
在PHP上,我使用的是"web3p/web3.php":"dev-master“、”web3p/ethereum“:"^0.4.3”库。
当我发送签名的事务时,我总是收到一个“无效的发送方”响应。事务数据是使用nodejs上工作良好的1inch.exchange API生成的。
我在PHP7.4上安装了GMP。
下面是我的脚本的short版本
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(); });我曾经尝试过,无论有没有包括现在,从和链子在交易帕拉姆。
我使用的是Moralis节点,但是Ankr节点也是如此。当我运行脚本的nodejs版本时,两个节点都能正常工作。
我已经挣扎了几天了,任何帮助都会很感激的。
谢谢!
发布于 2022-04-25 14:08:58
看看这个github问题。检查您的chainId格式。在bsc testnet中,我发现了以下内容:
'chainId' => 97 //works
'chainId' => 0x61 //works
'chainId' => '97' //works
'chainId' => '0x61' //invalid sender发布于 2022-08-02 17:43:45
我对web3p也有同样的问题。结束了我自己基于kornrunner签名者的方法:
https://github.com/drlecks/Simple-Web3-Php
我做了一个工作的“发送eth”的例子(例如/example.send.php),测试了etherum (mainnet),ropsten (etherum testnet)和孟买(多边形testnet)。
https://ethereum.stackexchange.com/questions/120873
复制相似问题