1

I'm writing a crypto based system with PHP on Infura, and now I am coding a script to retrieve logs for a specific address. This is my code:

$ch = curl_init($my_server_url);

$data = array(
    'jsonrpc' => '2.0',
    'id' => 1,
    'method' => 'eth_getLogs',
    'params' => array(array('address'=>'0x7d8f5F4ACa6Ca7Eb857A9F36d46b0aA715a88849'))
);
$payload = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
echo $result;

But nothing is returned at the end of execution whereas I had 2 transactions on this address. I receive this final result only:

{
   "jsonrpc": "2.0",
   "id": 1,
   "result": []
}

May you please tell me where is my mistake here?

  • 1
    According to etherscan, there was only one transaction on this address, which was a simple transfer of ether, for which there aren't any events, since no function is invoked (unless it's the address of a contract, which doesn't seem to be your case). – goodvibration Jan 4 at 6:58
  • Some Tether USDT also came to this address. You can find them on ERC20 Tokens. However, even if consider only Ethers, again I have nothing in returned log based on Infura system! – Mohammad Saberi Jan 4 at 7:01
  • Maybe I am wrong and this method is not to retrieve the logs of a specific Ethereum address at all. I wonder to build a mechanism to get the history of an Ethereum address using such API. – Mohammad Saberi Jan 4 at 7:11
  • I'd recommend using web3.js instead of whatever it is you're doing in PHP, which I believe to be much less used by the community. – goodvibration Jan 4 at 7:21
  • 2
    I don't think that there's a problem with eth_getLogs. Like I said, this address is of an externally-owned account, not of a smart-contract. So there cannot be any events emitted from this address. There can be some other contract which has emitted an event with this address being one of the parameters of, but you'd need to call eth_getLogs on the address of that other contract, not on the address of this externally-owned account of yours (specified in this question). – goodvibration Jan 4 at 7:41
2

Events are emitted by contracts, but the address 0x7d8f5F4ACa6Ca7Eb857A9F36d46b0aA715a88849 you use is not a contract. But the address has three related Erc20 Token transactions.

Let's assume you like to see the events from the related contract 0xdac17f958d2ee523a2206206994597c13d831ec7.

You have to filter the topic with your specific account, like in the following example:

    <?php 
    $my_server_url = "https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_KEY";
    $ch = curl_init($my_server_url);
    $data = array(
        'jsonrpc' => '2.0',
        'id' => 1,
        'method' => 'eth_getLogs',
        'params' => array(array(
            "fromBlock" => "0x0",
            "toBlock"   => "latest",
            "topics" => array(null, null, "0x0000000000000000000000007d8f5F4ACa6Ca7Eb857A9F36d46b0aA715a88849"),
            "address"   => "0xdAC17F958D2ee523a2206206994597C13D831ec7"
        ))
    );
    $payload = json_encode($data);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);
    echo $result;

The result will be:

  {
    "jsonrpc": "2.0",
    "id": 1,
    "result": [
      {
        "address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
        "blockHash": "0x688cdbabf192c897d54ccee88e8523b69fc6a52929670206f2596c969c416e78",
        "blockNumber": "0x8c39ab",
        "data": "0x00000000000000000000000000000000000000000000000000000000002dc6c0",
        "logIndex": "0x3",
        "removed": false,
        "topics": [
          "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
          "0x0000000000000000000000003f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be",
          "0x0000000000000000000000007d8f5f4aca6ca7eb857a9f36d46b0aa715a88849"
        ],
        "transactionHash": "0x4d8f2afd9a312bc93d357f36be845675d3531d2f05b476e8789ec22ef57e5fbe",
        "transactionIndex": "0x4"
      },
      {
        "address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
        "blockHash": "0x94e9257a373e5a7bb84ef035744d8aca0a29d0ebbc18f252fc39920dc0f37935",
        "blockNumber": "0x8c95c0",
        "data": "0x00000000000000000000000000000000000000000000000000000000001e8480",
        "logIndex": "0x5",
        "removed": false,
        "topics": [
          "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
          "0x000000000000000000000000e8670d7251573033b95065e0e2d6db9b08fdb683",
          "0x0000000000000000000000007d8f5f4aca6ca7eb857a9f36d46b0aa715a88849"
        ],
        "transactionHash": "0x281fed746f05f9fad14d8ab4fb9172b50199927fd70a7ee196bda3df100da893",
        "transactionIndex": "0x7"
      },
      {
        "address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
        "blockHash": "0x55fb9aeb0a66243117ef3a9295b7c06b0a4b8e139dc6312946cf7895b4acb19b",
        "blockNumber": "0x8c971b",
        "data": "0x00000000000000000000000000000000000000000000000000000000000f4240",
        "logIndex": "0x67",
        "removed": false,
        "topics": [
          "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
          "0x000000000000000000000000e8670d7251573033b95065e0e2d6db9b08fdb683",
          "0x0000000000000000000000007d8f5f4aca6ca7eb857a9f36d46b0aa715a88849"
        ],
        "transactionHash": "0x46e804c7acaaf3e86fc257f676fb552ce7176fdd4462a8acb252cbd791a594e8",
        "transactionIndex": "0x82"
      }
    ]
  }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.