

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Amazon Managed Blockchain (AMB) 查詢的使用案例
<a name="query-usecases"></a>

本主題提供清單 AMB 查詢使用案例。

**Topics**
+ [查詢目前和歷史權杖餘額](#query-token-balances)
+ [擷取歷史交易資料](#query-transactions)
+ [取得指定地址的所有字符餘額](#query-token-balances)
+ [列出為交易發出的事件](#query-tokens-minted)
+ [取得合約開採的所有字符](#query-transaction-events)
+ [列出合約並取得合約資訊](#query-contract-info)

## 查詢目前和歷史權杖餘額
<a name="query-token-balances"></a>

[https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_GetTokenBalance.html](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_GetTokenBalance.html) API 會使用外部擁有的帳戶 (EOAs) 的通用時間戳記 (Unix 時間戳記，以秒為單位），取得支援字符 (ERC20ERC721, ERC1155) 和原生金幣 (ETH、BTC) 的餘額，以取得目前或歷史餘額。例如，您可以使用 `GetTokenBalance` API 操作，在 Ethereum Mainnet 上取得 ERC20 權杖 USDC 的地址餘額。您也可以使用 `BatchGetTokenBalance` API 操作批次擷取權杖和原生金幣的平衡。

如需詳細資訊，請參閱《[Amazon Managed Blockchain (AMB) 查詢參考指南](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/Welcome.html)》。

## 擷取歷史交易資料
<a name="query-transactions"></a>

使用 Amazon Managed Blockchain (AMB) 查詢，您可以從 Ethereum 和 Bitcoin 等公有區塊鏈擷取歷史資料。此功能可啟用數個使用案例，例如擷取區塊鏈錢包上的交易歷史記錄，或根據交易雜湊提供交易的相關內容資訊。您可以使用 [https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_ListTransactions.html](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_ListTransactions.html) API 操作在 Ethereum Mainnet 上取得指定外部擁有地址 (EOA) 的交易清單，然後使用 [https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_GetTransaction.html](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_GetTransaction.html) API 操作從清單中擷取單一交易的交易詳細資訊。

如需詳細資訊，請參閱《[Amazon Managed Blockchain (AMB) 查詢參考指南](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/Welcome.html)》。

## 取得指定地址的所有字符餘額
<a name="query-token-balances"></a>

您可以使用 [https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_ListTokenBalances.html](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_ListTokenBalances.html) API 操作來取得錢包、使用者介面、Web3 公用程式等項目的平衡。此 API 操作會使用單一 API 操作，傳回指定公有區塊鏈上跨字符 (ERC20、ERC721, ERC1155和原生金幣 (ETH、BTC) 之地址的所有餘額清單。例如，您可以提供外部擁有的地址 (EOA) 和網路 (Ethereum Mainnet)，而且您可以在回應中收到字符和原生金幣餘額的清單。

如需詳細資訊，請參閱《[Amazon Managed Blockchain (AMB) 查詢參考指南](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/Welcome.html)》。

## 列出為交易發出的事件
<a name="query-tokens-minted"></a>

您可以使用 [https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_ListTransactionEvents.html](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_ListTransactionEvents.html) API 操作來擷取因指定交易而發出的合約事件清單，並以其雜湊 （交易識別符） 識別。例如，您可以使用 [https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_ListTransactionEvents.html](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_ListTransactionEvents.html)來擷取呼叫 Ethereum Blockchain 上 ERC20 字符合約函數的交易產生事件，例如 *Transfer* 事件或 ERC20 合約的*撤回*事件。

如需詳細資訊，請參閱《[Amazon Managed Blockchain (AMB) 查詢參考指南](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/Welcome.html)》。

## 取得合約開採的所有字符
<a name="query-transaction-events"></a>

您可以使用 [https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_ListTokenBalances.html](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_ListTokenBalances.html) API 操作，傳回在傳遞合約地址做為輸入時，由合約開採的所有支援字符 (ERC20、ERC721, ERC1155清單。例如，您可以使用 [https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_ListTokenBalances.html](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/API_ListTokenBalances.html) API 操作，擷取由 Ethereum 區塊鏈上 ERC721 合約標準開採的非可信任權杖 (NFTs) 相關資訊。

如需詳細資訊，請參閱《[Amazon Managed Blockchain (AMB) 查詢參考指南](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/Welcome.html)》。

## 列出合約並取得合約資訊
<a name="query-contract-info"></a>

您可以使用 [https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/ListAssetContracts.html](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/ListAssetContracts.html) API 操作來列出由指定地址部署ERC-721, ERC-1155 或 ERC-20 合約。此外，如果您有合約地址，您可以使用 [https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/ListAssetContracts.html](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/ListAssetContracts.html) API 操作來擷取合約的屬性，例如合約類型部署程式地址和相關的字符中繼資料。

如需詳細資訊，請參閱《[Amazon Managed Blockchain (AMB) 查詢參考指南](https://docs.aws.amazon.com/managed-blockchain/latest/AMBQ-APIReference/Welcome.html)》。