From de5adb5f8e6633a1f4191f2a7e1daa4e90a7dc3a Mon Sep 17 00:00:00 2001 From: Nazeim Date: Tue, 24 Oct 2023 23:20:22 +0300 Subject: [PATCH 1/3] Get transactions of a smart contract account --- ...ive-balance-of-a-smart-contract-account.md | 8 +- ...-transactions-of-smart-contract-account.md | 209 ++++++++++++++++++ 2 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 docs/01-web3-data-api/evm/wallet-api/05-Transactions/how-to-get-transactions-of-smart-contract-account.md diff --git a/docs/01-web3-data-api/evm/wallet-api/02-Native balance/how-to-get-the-native-balance-of-a-smart-contract-account.md b/docs/01-web3-data-api/evm/wallet-api/02-Native balance/how-to-get-the-native-balance-of-a-smart-contract-account.md index 9eb861a78..59edf5d99 100644 --- a/docs/01-web3-data-api/evm/wallet-api/02-Native balance/how-to-get-the-native-balance-of-a-smart-contract-account.md +++ b/docs/01-web3-data-api/evm/wallet-api/02-Native balance/how-to-get-the-native-balance-of-a-smart-contract-account.md @@ -13,7 +13,7 @@ There are two primary account types: **Contract Accounts** function autonomously, controlled by pre-defined smart contract code without private keys. -:::note +:::tip As an example of account types, you can read the [Ethereum Accounts](https://ethereum.org/en/developers/docs/accounts/#types-of-account) article. ::: @@ -54,7 +54,7 @@ const runApp = async() => { }); // Define the address of a smart contract account for which you want to fetch the native balance - const address = '0x350845DD3f03F1355233a3A7CEBC24b5aAD05eC5'; + const address = "0x350845DD3f03F1355233a3A7CEBC24b5aAD05eC5"; // Specify the blockchain that you are working with (e.g., Ethereum) const chain = EvmChain.ETHEREUM; @@ -172,3 +172,7 @@ Should you encounter any challenges while following this tutorial, our community ## API Reference If you want to explore more details about other wallet endpoints and optional parameters, refer to the [API Reference](/web3-data-api/evm/reference#wallet-api). + +## See Also + +* [How to Get Transaction History for an Address of a Smart Account](/web3-data-api/evm/wallet-api/how-to-get-transactions-of-smart-contract-account) diff --git a/docs/01-web3-data-api/evm/wallet-api/05-Transactions/how-to-get-transactions-of-smart-contract-account.md b/docs/01-web3-data-api/evm/wallet-api/05-Transactions/how-to-get-transactions-of-smart-contract-account.md new file mode 100644 index 000000000..8dfb218e3 --- /dev/null +++ b/docs/01-web3-data-api/evm/wallet-api/05-Transactions/how-to-get-transactions-of-smart-contract-account.md @@ -0,0 +1,209 @@ +--- +title: "How to Get Transaction History for an Address of a Smart Account" +slug: "../how-to-get-transactions-of-smart-contract-account" +description: "Understanding Account Abstraction and how to get all transactions from a smart contract account using Moralis Wallet API." +sidebar_label: Get transactions of a smart contract account" +--- + +:::tip +As an example of account types, you can read the [Ethereum Accounts](https://ethereum.org/en/developers/docs/accounts/#types-of-account) article. +::: + +Moralis Wallet API streamlines the retrieval of transaction history, making it easier for developers to access and use transaction data for various purposes. + +**Why Retrieve Address Transaction History?** + +1. **Display Full Transaction History:** Provide users with a complete view of their blockchain transactions for wallet and financial tracking. + +2. **Filter Smart Contract Interactions:** Easily review transactions related to smart contract interactions for auditing and analysis. + +3. **Analyze Profit and Loss:** Calculate gains and losses by accessing historical transaction data for investment evaluation. + +4. **Security Auditing:** Conduct security audits and vulnerability assessments on smart contracts and blockchain applications. + +5. **Dispute Resolution:** Resolve disputes and investigate discrepancies using an objective transaction record. + +Learn the most efficient method for obtaining and getting a complete transaction history for smart contract accounts. It includes external, internal, token, ERC-20, ERC-721, and ERC-1155 token transfers, all in a single API request. + +This step-by-step tutorial shows how to retrieve transactions from a smart account, simplifying the process and offering code examples in multiple programming languages. + +:::tip +This tutorial uses Moralis [getWalletTransactions](/web3-data-api/evm/reference/get-wallet-transactions) RPC method. +::: + +## Step 1: Setup Moralis + +Read the article [Setting Up Moralis: Getting Started](/web3-data-api/evm/get-your-api-key) and make sure to finish all the steps. Only after that you can go ahead to complete this guide. + +## Step 2: Method to Get and Retrieve Transactions for a Given Smart Account Address + +You can use the API endpoint [getWalletTransactions](/web3-data-api/evm/reference/get-wallet-transactions) to get all transactions for an address of a smart account. This endpoint allows you to fetch transactions for a given address of a smart account. + +You will need two essential parameters: + +* `address` +* `chain` + +Once you have obtained both the `address` and `chain`, you can use the code snippets below to retrieve the transactions: + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + + + + +```javascript +// Import Moralis and EvmChain from required libraries +const Moralis = require("moralis").default; +const { EvmChain } = require("@moralisweb3/common-evm-utils"); + +// Define the main function to retrieve transactions +const runApp = async () => { + // Initialize Moralis with your API key and other configurations + await Moralis.start({ + apiKey: "YOUR_API_KEY", + // ...and any other configuration + }); + + // Define the Smart account address you want to retrieve transactions for + const address = "0x350845DD3f03F1355233a3A7CEBC24b5aAD05eC5"; + + // Specify the Ethereum chain (e.g., ETHEREUM) for the transactions + const chain = EvmChain.ETHEREUM; + + // Use Moralis.EvmApi.transaction.getWalletTransactions to fetch transactions + const response = await Moralis.EvmApi.transaction.getWalletTransactions({ + address, + chain, + }); + + // Log the JSON response + console.log(response.toJSON()); +}; + +// Run the main function to retrieve transactions +runApp(); +``` + + + + +```typescript +// Import Moralis and EvmChain from required libraries +import Moralis from "moralis"; +import { EvmChain } from "@moralisweb3/common-evm-utils"; + +// Define the main function to retrieve transactions +const runApp = async () => { + // Initialize Moralis with your API key and other configurations + await Moralis.start({ + apiKey: "YOUR_API_KEY", + // ...and any other configuration + }); + + // Define the Smart account address you want to retrieve transactions for + const address = "0x350845DD3f03F1355233a3A7CEBC24b5aAD05eC5"; + + // Specify the Ethereum chain (e.g., ETHEREUM) for the transactions + const chain = EvmChain.ETHEREUM; + + // Use Moralis.EvmApi.transaction.getWalletTransactions to fetch transactions + const response = await Moralis.EvmApi.transaction.getWalletTransactions({ + address, + chain, + }); + + // Log the JSON response + console.log(response.toJSON()); +}; + +// Run the main function to retrieve transactions +runApp(); + +``` + + + + +```python +# Import the required module from Moralis +from moralis import evm_api + +# Define your API key +api_key = "YOUR_API_KEY" + +# Define parameters for retrieving transactions +params = { + "address": "0x350845DD3f03F1355233a3A7CEBC24b5aAD05eC5", + "chain": "eth", +} + +# Use evm_api.transaction.get_wallet_transactions to fetch transactions +result = evm_api.transaction.get_wallet_transactions( + api_key=api_key, + params=params, +) + +# Print the result +print(result) +``` + + + + +## Step 3: Run the Script + +import RunTheScript from '/docs/partials/\_run-the-script.mdx'; + + + +Code example pf the JSON response: + +```json +{ + "total": "2000", + "page": "2", + "page_size": "100", + "result": [ + { + "hash": "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e", + "nonce": 326595425, + "transaction_index": 25, + "from_address": "0xd4a3BebD824189481FC45363602b83C9c7e9cbDf", + "to_address": "0xa71db868318f0a0bae9411347cd4a6fa23d8d4ef", + "value": 650000000000000000, + "gas": 6721975, + "gas_price": 20000000000, + "input": "string", + "receipt_cumulative_gas_used": 1340925, + "receipt_gas_used": 1340925, + "receipt_contract_address": "0x1d6a4cf64b52f6c73f201839aded7379ce58059c", + "receipt_root": "string", + "receipt_status": 1, + "block_timestamp": "2021-04-02T10:07:54.000Z", + "block_number": 12526958, + "block_hash": "0x0372c302e3c52e8f2e15d155e2c545e6d802e479236564af052759253b20fd86" + } + ] +} +``` + +Congratulations 🥳! You have successfully fetched transactions for a given smart account address on Ethereum using the Moralis Wallet API. + +## Video Tutorial: Get All Transactions For Any Wallet + +For a visual guide, you can check out our YouTube tutorial: + +[Watch the Tutorial](https://www.youtube.com/watch?v=kpxgYuC4uyA) + +## Get 24/7 Developer Support + +Should you encounter any challenges while following this tutorial, our community engineers are here to assist you. Reach out to us on [Discord](https://moralis.io/discord) or [Forum](https://forum.moralis.io) to receive 24/7 developer support. Your success is our priority! + +## API Reference + +If you want to explore more details about other wallet endpoints and optional parameters, refer to the [API Reference](/web3-data-api/evm/reference#wallet-api). + +## See Also + +* [Understanding Account Abstraction: How to Get Native Balances from Smart Accounts](/web3-data-api/evm/wallet-api/how-to-get-the-native-balance-of-a-smart-contract-account) From 2511b173af1d4553064dccce42991fce3e92f70e Mon Sep 17 00:00:00 2001 From: Nazeim Date: Thu, 26 Oct 2023 21:27:36 +0300 Subject: [PATCH 2/3] fix typo --- .../how-to-get-transactions-of-smart-contract-account.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/01-web3-data-api/evm/wallet-api/05-Transactions/how-to-get-transactions-of-smart-contract-account.md b/docs/01-web3-data-api/evm/wallet-api/05-Transactions/how-to-get-transactions-of-smart-contract-account.md index 8dfb218e3..4512a0eb3 100644 --- a/docs/01-web3-data-api/evm/wallet-api/05-Transactions/how-to-get-transactions-of-smart-contract-account.md +++ b/docs/01-web3-data-api/evm/wallet-api/05-Transactions/how-to-get-transactions-of-smart-contract-account.md @@ -2,7 +2,7 @@ title: "How to Get Transaction History for an Address of a Smart Account" slug: "../how-to-get-transactions-of-smart-contract-account" description: "Understanding Account Abstraction and how to get all transactions from a smart contract account using Moralis Wallet API." -sidebar_label: Get transactions of a smart contract account" +sidebar_label: Get transactions of a smart contract account --- :::tip @@ -157,7 +157,7 @@ import RunTheScript from '/docs/partials/\_run-the-script.mdx'; -Code example pf the JSON response: +Code example of the JSON response: ```json { From a55c3562825af59f86c92c2ed1b5df214b2bb342 Mon Sep 17 00:00:00 2001 From: son-of-crypto <97063882+son-of-crypto@users.noreply.github.com> Date: Fri, 27 Oct 2023 11:14:58 -0400 Subject: [PATCH 3/3] Update how-to-get-transactions-of-smart-contract-account.md --- ...-transactions-of-smart-contract-account.md | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/01-web3-data-api/evm/wallet-api/05-Transactions/how-to-get-transactions-of-smart-contract-account.md b/docs/01-web3-data-api/evm/wallet-api/05-Transactions/how-to-get-transactions-of-smart-contract-account.md index 4512a0eb3..60900a0ee 100644 --- a/docs/01-web3-data-api/evm/wallet-api/05-Transactions/how-to-get-transactions-of-smart-contract-account.md +++ b/docs/01-web3-data-api/evm/wallet-api/05-Transactions/how-to-get-transactions-of-smart-contract-account.md @@ -1,7 +1,7 @@ --- title: "How to Get Transaction History for an Address of a Smart Account" slug: "../how-to-get-transactions-of-smart-contract-account" -description: "Understanding Account Abstraction and how to get all transactions from a smart contract account using Moralis Wallet API." +description: "Understanding account abstraction and how to get all transactions from a smart contract account using the Moralis Wallet API." sidebar_label: Get transactions of a smart contract account --- @@ -9,7 +9,7 @@ sidebar_label: Get transactions of a smart contract account As an example of account types, you can read the [Ethereum Accounts](https://ethereum.org/en/developers/docs/accounts/#types-of-account) article. ::: -Moralis Wallet API streamlines the retrieval of transaction history, making it easier for developers to access and use transaction data for various purposes. +The Moralis Wallet API streamlines the retrieval of transaction history, making it easier for developers to access and use transaction data for various purposes. **Why Retrieve Address Transaction History?** @@ -28,23 +28,23 @@ Learn the most efficient method for obtaining and getting a complete transaction This step-by-step tutorial shows how to retrieve transactions from a smart account, simplifying the process and offering code examples in multiple programming languages. :::tip -This tutorial uses Moralis [getWalletTransactions](/web3-data-api/evm/reference/get-wallet-transactions) RPC method. +This tutorial uses Moralis' [`getWalletTransactions`](/web3-data-api/evm/reference/get-wallet-transactions) RPC method. ::: -## Step 1: Setup Moralis +## Step 1: Set Up Moralis -Read the article [Setting Up Moralis: Getting Started](/web3-data-api/evm/get-your-api-key) and make sure to finish all the steps. Only after that you can go ahead to complete this guide. +Read our article, [Setting Up Moralis: Getting Started](/web3-data-api/evm/get-your-api-key), and make sure to finish all the steps. Only after that can you go ahead to complete this guide. ## Step 2: Method to Get and Retrieve Transactions for a Given Smart Account Address -You can use the API endpoint [getWalletTransactions](/web3-data-api/evm/reference/get-wallet-transactions) to get all transactions for an address of a smart account. This endpoint allows you to fetch transactions for a given address of a smart account. +You can use the [`getWalletTransactions`](/web3-data-api/evm/reference/get-wallet-transactions) API endpoint to get all transactions for an address of a smart account. This endpoint allows you to fetch transactions for a given address of a smart account. You will need two essential parameters: * `address` * `chain` -Once you have obtained both the `address` and `chain`, you can use the code snippets below to retrieve the transactions: +Once you have obtained both `address` and `chain`, you can use the code snippets below to retrieve the transactions: import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; @@ -65,7 +65,7 @@ const runApp = async () => { // ...and any other configuration }); - // Define the Smart account address you want to retrieve transactions for + // Define the smart account address you want to retrieve transactions for const address = "0x350845DD3f03F1355233a3A7CEBC24b5aAD05eC5"; // Specify the Ethereum chain (e.g., ETHEREUM) for the transactions @@ -101,7 +101,7 @@ const runApp = async () => { // ...and any other configuration }); - // Define the Smart account address you want to retrieve transactions for + // Define the smart account address you want to retrieve transactions for const address = "0x350845DD3f03F1355233a3A7CEBC24b5aAD05eC5"; // Specify the Ethereum chain (e.g., ETHEREUM) for the transactions @@ -188,9 +188,9 @@ Code example of the JSON response: } ``` -Congratulations 🥳! You have successfully fetched transactions for a given smart account address on Ethereum using the Moralis Wallet API. +Congratulations! 🥳 You have successfully fetched transactions for a given smart account address on Ethereum using the Moralis Wallet API. -## Video Tutorial: Get All Transactions For Any Wallet +## Video Tutorial: Get All Transactions for Any Wallet For a visual guide, you can check out our YouTube tutorial: @@ -198,11 +198,11 @@ For a visual guide, you can check out our YouTube tutorial: ## Get 24/7 Developer Support -Should you encounter any challenges while following this tutorial, our community engineers are here to assist you. Reach out to us on [Discord](https://moralis.io/discord) or [Forum](https://forum.moralis.io) to receive 24/7 developer support. Your success is our priority! +Should you encounter any challenges while following this tutorial, our community engineers are here to assist you. Reach out to us on [Discord](https://moralis.io/discord) or our [Moralis forum](https://forum.moralis.io) to receive 24/7 developer support. Your success is our priority! ## API Reference -If you want to explore more details about other wallet endpoints and optional parameters, refer to the [API Reference](/web3-data-api/evm/reference#wallet-api). +If you want to explore more details about other wallet endpoints and optional parameters, check out our [API Reference](/web3-data-api/evm/reference#wallet-api) page. ## See Also