只是为那些看到这个未来的人添加更多关于解决方案的细节。
通过使用 Moralis API,您可以通过将合约地址、事件名称和事件 ABI 作为查询参数传递来获取合约过去的所有 transfer 事件。下面是示例代码。
<?php
// Dependencies to install:
// $ composer require guzzlehttp/guzzle
require_once('vendor/autoload.php');
$client = new GuzzleHttpClient();
$response = $client->request('POST', 'https://deep-index.moralis.io/api/v2/0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984/events?chain=eth&topic=0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', [
'body' => '{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Transfer","type":"event"}',
'headers' => [
'Accept' => 'application/json',
'X-API-Key' => 'Moralis_API_Key',
'Content-Type' => 'application/json',
],
]);
echo $response->getBody();
在以下位置查找更多信息:https://docs.moralis.io/web3-data-api/reference/get-contract-events
但是,如果您没有合约 ABI,您仍然可以仅使用合约地址获取所有 NFT/NFT Id。这是一个示例代码。
<?php
// Dependencies to install:
// $ composer require guzzlehttp/guzzle
require_once('vendor/autoload.php');
$client = new GuzzleHttpClient();
$response = $client->request('GET', 'https://deep-index.moralis.io/api/v2/nft/0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB?chain=eth&format=decimal', [
'headers' => [
'Accept' => 'application/json',
'X-API-Key' => 'Moralis_API_Key',
],
]);
echo $response->getBody();
在以下位置查找更多信息:https://docs.moralis.io/web3-data-api/reference/get-contract-nfts
希望这可以帮助。