$web3
= new Web3(new HttpProvider(new HttpRequestManager(self::RPC_HOST)));
$contract = self::loadContract($web3); //ok
$fid = self::newTopicFilter($contract); //something wrong, report an error, but I don't know why .
self::monitorLoop($contract, $fid);
static public function newTopicFilter($contract)
{
$cb = new Callback;
$topics = [];
$contract->eth->newFilter($topics, $cb);
return $cb->result;
}
static public function monitorLoop($contract, $fid)
{
$cb = new Callback;
//$topic = $contract->ethabi->encodeEventSignature($contract->events['Transfer']);
$topic
= $contract->ethabi->encodeEventSignature($contract->events['Approval']);
echo $topic.PHP_EOL;
while (true) {
$contract->eth->getFilterChanges($fid, $cb);
$logs = $cb->result;
if (count($logs) > 0) {
foreach ($logs as $log) {
if ($log->topics[0] == $topic) {
var_dump($log);
} else {
echo 'skip log '.PHP_EOL;
}
}
}
sleep(2);
}
}
below is the full error:
php log-monitor-topic.php PHP Fatal error: Uncaught RuntimeException: invalid argument 0: json: cannot unmarshal array into Go value of type fil ters.input in /home/user/repo/vendor/sc0vu/web3.php/src/RequestManagers/HttpRequestManager.php:114 Stack trace: #0 /home/user/repo/vendor/sc0vu/web3.php/src/Providers/HttpProvider.php(62): Web3\RequestManagers\HttpRequestManager->s endPayload('{"id":409131478...', Object(Closure)) #1 /home/user/repo/vendor/sc0vu/web3.php/src/Eth.php(105): Web3\Providers\HttpProvider->send(Object(Web3\Methods\Eth\Ne wFilter), Object(EthTool\Callback)) #2 /home/user/repo/chapter6/log-monitor-topic.php(24): Web3\Eth->__call('newFilter', Array) #3 /home/user/repo/chapter6/log-monitor-topic.php(14): newTopicFilter(Object(Web3\Contract)) #4 {main} thrown in /home/user/repo/vendor/sc0vu/web3.php/src/RequestManagers/HttpRequestManager.php on line 114
I want to monitor BSC-USDT event
below is the full error:
php log-monitor-topic.php PHP Fatal error: Uncaught RuntimeException: invalid argument 0: json: cannot unmarshal array into Go value of type fil ters.input in /home/user/repo/vendor/sc0vu/web3.php/src/RequestManagers/HttpRequestManager.php:114 Stack trace: #0 /home/user/repo/vendor/sc0vu/web3.php/src/Providers/HttpProvider.php(62): Web3\RequestManagers\HttpRequestManager->s endPayload('{"id":409131478...', Object(Closure)) #1 /home/user/repo/vendor/sc0vu/web3.php/src/Eth.php(105): Web3\Providers\HttpProvider->send(Object(Web3\Methods\Eth\Ne wFilter), Object(EthTool\Callback)) #2 /home/user/repo/chapter6/log-monitor-topic.php(24): Web3\Eth->__call('newFilter', Array) #3 /home/user/repo/chapter6/log-monitor-topic.php(14): newTopicFilter(Object(Web3\Contract)) #4 {main} thrown in /home/user/repo/vendor/sc0vu/web3.php/src/RequestManagers/HttpRequestManager.php on line 114