2
submitted 1 year ago by [email protected] to c/[email protected]

Introduction

Definition of ERC-20 Tokens

ERC-20 stands for "Ethereum Request for Comments 20," and it is a technical standard used for smart contracts on the Ethereum blockchain. These tokens are fungible and represent digital assets that can be exchanged, just like traditional currencies. They have gained immense popularity as they enable the creation of decentralized applications (DApps) and Initial Coin Offerings (ICOs) through the Ethereum platform.

Uses of ERC-20 Tokens

ERC-20 tokens have a wide range of applications. They can represent utility tokens, providing access to specific features or services within a DApp. Additionally, they can function as security tokens, offering ownership in a particular asset or company. Furthermore, ERC-20 tokens can be used for governance, allowing holders to participate in decision-making processes within a decentralized organization.

Importance of the ERC-20 Standard

Standardization Benefits

The ERC-20 standard brought much-needed uniformity to the token creation process on the Ethereum blockchain. Before its establishment, developers had to design custom code for each token, resulting in inefficiencies and potential security risks. The ERC-20 standard streamlined the token creation process, making it easier for developers to create tokens that are compatible with various wallets and exchanges. This compatibility has significantly contributed to the widespread adoption of ERC-20 tokens and the growth of the Ethereum ecosystem.

Mandatory ERC-20 Functions in Solidity

totalSupply()

The totalSupply() function is a mandatory ERC-20 function that returns the total number of tokens in circulation. It provides transparency regarding the token's overall supply, allowing users to verify the token's scarcity and value.

balanceOf()

The balanceOf() function is used to check the token balance of a specific Ethereum address. It is crucial for users to know their token holdings and manage their assets effectively.

transfer()

The transfer() function allows users to send ERC-20 tokens from their wallet to another Ethereum address. This function is the backbone of token transactions and facilitates the transfer of value within the Ethereum network.

approve()

The approve() function is essential for enabling secure and controlled token transfers. It allows the token holder to authorize another Ethereum address to withdraw a specific amount of tokens on their behalf.

transferFrom()

The transferFrom() function is closely related to the approve() function and is used to transfer tokens on behalf of another address with their consent.

allowance()

The allowance() function is used to check the number of tokens that a spender is allowed to withdraw from the token holder's account. It provides an additional layer of security and control over token transfers.

Optional ERC-20 Functions in Solidity

Name

The name function is an optional ERC-20 function that returns the name of the token. While not strictly necessary for the token's functionality, it adds a level of user-friendliness, as it helps users identify the purpose of the token.

Symbol

The symbol function is another optional ERC-20 function that returns the token's symbol. Similar to the name function, it aids users in quickly identifying and distinguishing between different tokens.

Decimals

The decimals function, also optional, returns the number of decimal places that the token uses to represent its smallest unit. This allows for better granularity in token values.

ERC-20 Data Structures

Balances Mapping

ERC-20 tokens use a data structure known as a "balances mapping" to keep track of the token balance for each Ethereum address. It associates the token balance with the corresponding Ethereum address, making it easy to verify ownership and conduct transfers.

Allowances Mapping

The "allowances mapping" is another critical data structure in ERC-20 tokens. It stores the approved token withdrawal amount for a specific spender address. This allows for controlled and secure token transfers on behalf of token holders.

Conclusion

ERC-20 tokens have revolutionized the world of blockchain and cryptocurrencies by providing a standardized and efficient way to create and manage digital assets. With a well-defined set of functions and data structures, ERC-20 tokens offer versatility and compatibility across various platforms. As blockchain technology continues to evolve, ERC-20 tokens will remain a fundamental building block for innovative decentralized applications and tokenized assets.

Start Building with Chainbase

The ERC-20 standard stands as the most vital specification to come out of Ethereum, owing to its widespread acceptance and integration into core smart contract protocols. For developers, taking time to fully understand ERC-20 and create your own token is strongly advised.

If you want to learn more in-depth details and programming concepts related to ERC-20 tokens, you are welcome to visit the ERC-20 related blogs on the Chainbase official website for more information.

About Chainbase

Chainbase is an all-in-one data infrastructure for Web3 that allows you to index, transform, and use on-chain data at scale. By leveraging enriched on-chain data and streaming computing technologies across one data infrastructure, Chainbase automates the indexing and querying of blockchain data, enabling developers to accomplish more with less effort.

Want to learn more about Chainbase?

Visit our website chainbase.com Sign up for a free account, and Check out our documentation.

WebsiteBlogTwitterDiscordLink3

The Original Link::Comprehensive Overview of Solidity ERC20 Tokens

1
submitted 1 year ago by [email protected] to c/[email protected]

Introduction

This tutorial will show you how to use the Chainbase API's getTopTokenHolders function to get the top holders of a cryptocurrency that is on the Ethereum blockchain. Knowing who holds the most tokens can be helpful for many reasons, such as reaching out to them for collaborations and keeping track of the flow of funds.

Table of Contents

  1. Overview - Tools you need to work with Chainbase
  2. Step 1: Set up a free account at Chainbase
  3. Step 2: Write a script using the Chainbase API
  4. Step 3: Print token holders
  5. Conclusion
  6. FAQs

1. Overview - Tools you need to work with Chainbase

To get started, you will need the following tools:

  • A free account at Chainbase with an API key.
  • An integrated development environment (IDE). We recommend using Visual Studio Code (VS Code).

2. Step 1: Set up a free account at Chainbase

To leverage the capabilities of Chainbase, follow these steps:

  • Register for a free account on the Chainbase website.
  • Log in to your Chainbase account and visit the dashboard to get an overview.
  • Create a new project in the console to obtain an API key.

Untitled

3. Step 2: Write a script using the Chainbase API

You can use JavaScript and the Chainbase API to retrieve the top token holders. Here are two examples using different libraries: fetch and axios.

Using fetch in JavaScript

javascriptCopy code
network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
token_addr = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'; // Take MATIC token address as an example.

fetch(`https://api.chainbase.online/v1/token/top-holders?chain_id=${network_id}&contract_address=${token_addr}&page=1&limit=5`, {
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
}).then(response => response.json())
    .then(data => console.log(data.data))
    .catch(error => console.error(error));

Using axios in JavaScript

You need to install axios using npm install axios --save in the terminal first.

javascriptCopy code
network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
token_addr = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'; // Take MATIC token address as an example.

const axios = require('axios');
const options = {
    url: `https://api.chainbase.online/v1/token/top-holders?chain_id=${network_id}&contract_address=${token_addr}&page=1&limit=5`,
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
};
axios(options)
    .then(response => console.log(response.data.data))
    .catch(error => console.log(error));

4. Step 3: Print token holders

The getTopTokenHolders function from the Chainbase API requires the chain ID and the contract address of the ERC20 token as input parameters. This function returns information regarding the top token holders. Also, you can use the page and limit parameters for pagination and to retrieve a specific number of top holders.

To print the token holders, execute the command node .js in the terminal, where `` represents the name of your script. Here is an example of the expected JSON data returned by the API:

jsonCopy code
{
  "count": 593525,
  "holders": [
    {
      "wallet_address": "0x5e3ef299fddf15eaa0432e6e66473ace8c13d908",
      "amount": "3814264335.329752",
      "usd_value": "4167560569.389670"
    },
    {
      "wallet_address": "0x401f6c983ea34274ec46f84d70b31c151321188b",
      "amount": "910440417.955799",
      "usd_value": "994769961.668955"
    },
    {
      "wallet_address": "0xcd6507d87f605f5e95c12f7c4b1fc3279dc944ab",
      "amount": "590639315.000000",
      "usd_value": "645347281.551875"
    },
    {
      "wallet_address": "0xb316fa9fa91700d7084d377bfdc81eb9f232f5ff",
      "amount": "434226114.715070",
      "usd_value": "474446308.590553"
    },
    {
      "wallet_address": "0xcbfe11b78c2e6cb25c6eda2c6ff46cd4755c8fca",
      "amount": "273304816.000000",
      "usd_value": "298619674.582000"
    }
  ]
}

5. Conclusion

By following the tutorial steps, you have learned how to use the Chainbase API's getTopTokenHolders function to get details about the top holders of an ERC20 token deployed on the Ethereum blockchain.

6. FAQs

Q1: Can I use the Chainbase API for tokens deployed on other blockchain networks?

Currently, we only provide information on Ethereum ERC-20 token holders. Data on additional chains will be available soon.

Q2: How can I increase the number of token holders fetched?

You can adjust the limit parameter in the API request to fetch more token holders. Increase the value to retrieve a larger list, bearing in mind that excessively high values may impact performance.

Q3: Is it possible to sort the token holders based on their holdings?

The Chainbase API already returns the token holders in descending order based on their holdings. The first holder in the list represents the top holder.

Q4: Can I obtain additional information about the token holders?

Yes, the API response provides the wallet address, the amount of tokens held, and the equivalent USD value. You can use this data to analyze and engage with the token holders.

Q5: How frequently does the Chainbase API update the token holder information?

Our API is unique in the industry because it provides real-time token holder information that can be sorted. Other APIs, like those used in browsers, usually have a cache value that lasts about 20 minutes.


About Chainbase

Chainbase is an all-in-one data infrastructure for Web3 that allows you to index, transform, and use on-chain data at scale. By leveraging enriched on-chain data and streaming computing technologies across one data infrastructure, Chainbase automates the indexing and querying of blockchain data, enabling developers to accomplish more with less effort.

Want to learn more about Chainbase?

Visit our website chainbase.com Sign up for a free account, and Check out our documentation.

WebsiteBlogTwitterDiscordLink3

0
submitted 1 year ago by [email protected] to c/[email protected]

Introduction

In the world of cryptocurrency, knowing the holders of a particular token can provide valuable insights and opportunities for collaboration. Chainbase, a leading platform, offers a powerful API called getTokenHolders that allows you to retrieve a list of addresses for all the holders of a specific ERC20 token. This tutorial will guide you through the process of using Chainbase API to get the holders of a cryptocurrency deployed on various chains. By leveraging this information, you can devise strategies to engage with these holders and enhance the overall value of your cryptocurrency.

Outline:

Overview - Tools you need to work with Chainbase Step 1: Set up a free account at Chainbase Step 2: Write a script using Chainbase API Step 3: Print token holders Conclusion FAQs

Overview - Tools you need to work with Chainbase

To interact with the Chainbase API and retrieve NFT ownership information, you'll need the following:

  • A free account at Chainbase with an API key.
  • An Integrated Development Environment (IDE) such as Visual Studio Code.
  • The contract address of a known NFT collection and the token ID of the specific NFT you want to query.

Step 1: Set up a free account at Chainbase

To take full advantage of Chainbase's capabilities, you need to create a free account. Follow these steps:

  1. Register for a free account on the Chainbase website.
  2. Once registered, log in to your account and visit the dashboard to gain an overview of the available features.
  3. Create a new project within the Chainbase console.
  4. Obtain an API key associated with your project.

Step 2: Write a script using Chainbase API

To fetch the holders of an ERC20 token, you need to write a script that interacts with the Chainbase API. We'll demonstrate two methods using JavaScript: fetch and axios.

Using fetch in JavaScript


network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
token_addr = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'; // Take MATIC token address as an example.

fetch(`https://api.chainbase.online/v1/token/holders?chain_id=${network_id}&contract_address=${token_addr}&page=1&limit=20`, {
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
}).then(response => response.json())
    .then(data => console.log(data.data))
    .catch(error => console.error(error));

Using axios in JavaScript

You need to install it by running npm install axios --save in your terminal.


network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
token_addr = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'; // Take MATIC token address as an example.

const axios = require('axios');
const options = {
    url: `https://api.chainbase.online/v1/token/holders?chain_id=${network_id}&contract_address=${token_addr}&page=1&limit=20`,
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
};
axios(options)
    .then(response => console.log(response.data.data))
    .catch(error => console.log(error));

Step 3: Print token holders

Chainbase API's getTokenHolders requires the chain ID and the contract address of the ERC20 token as parameters. It returns a list of token holders. You can also utilize pagination and set limits using the page and limit parameters.

To retrieve and print the data, execute the following command in your terminal: node .js. The returned data will be similar to the following example:


[
  "0xe31fcac26fccf1fda8a99b033bfae82c8c44df63",
  "0xf60328d7eabe4196a7d530721d4da5316c435fc5",
  "0x38a0c3aaaac2736915f0e5e7044aa6fd90c22f7e",
  "0xfa79dcccb2c4c8eaaf21de271020919e1a4b093e",
  "0x00e4487f5b43540614ddcb835b5afdabe19f1ed4",
  "0x2f13499c1e391896762b8c1a6c88390113ca54c4",
  "0xcad779f8b51f1043efbd365f6b7353670633415c",
  "0x880e295d5fabc24340b547146b29119a7aa3ce9f",
  "0xc75b46aea8538e6f1269d2fe73d1ca92002b1c37",
  "0x6067aedebf0704d178674b16dbf0d7c6c5d5d03e",
  "0xcd97b55b07d2a4f397ea513c0fd9f899fa01fbe1",
  "0xed6425f466ebd178fc3060a0d60eb1a609cf5558",
  "0x8c372e79195f0113942012e7e52dfe30c5606962",
  "0xbdc034c242e4ef08e56539bc6141c1e3847b60b9",
  "0x28c497c274bfae45bcadd2f19a941d346fc741ab",
  "0x1ad9a52e8d1f1e957415d3407ab9a8bdcf5decd1",
  "0x73c4eb25fadf7edb6087f130fea23a90aab88a65",
  "0xad270298f03ae7ed9f211fe25f4b90a2c711262d",
  "0xde85dfd2e53d0f01852a4a64d0e3ab644fb0e965",
  "0x51edc446851a6063c6489f575602e4482e9a0bff"
]

Please note that the order of token holders may vary each time due to the API returning unsorted data. If you specifically require the top token holders, you can explore another API called getTopTokenHolders.

Conclusion

Knowing the holders of an ERC20 token is essential for effective engagement and collaboration within the cryptocurrency ecosystem. Chainbase's getTokenHolders API empowers you to retrieve the addresses of all token holders with ease. By leveraging this information, you can develop strategies to enhance the value and impact of your cryptocurrency.

Now that you have learned how to use Chainbase's API to obtain token holders, you can explore new possibilities and create innovative solutions that contribute to the growth and success of your cryptocurrency.

FAQs

  1. Q: Can I use Chainbase's getTokenHolders API for any ERC20 token?

    A: Yes, you can utilize the getTokenHolders API for any ERC20 token deployed on supported chains.

  2. Q: How can I obtain an API key for Chainbase?

    A: Once you have created a free account on our website, you can generate an API key within the project dashboard.

  3. Q: Can I retrieve more than 20 token holders in a single API call?

    A: Yes, you can adjust the limit parameter in the API call to retrieve a higher number of token holders.

  4. Q: Are the token holders returned in a specific order?

    A: The getTokenHolders API returns unsorted token holders. If you need the top token holders, consider using the getTopTokenHolders API.

  5. Q: How often does the data of token holders change?

    A: The data of token holders can change frequently, depending on various factors such as transactions and token transfers.


About Chainbase

Chainbase is an all-in-one data infrastructure for Web3 that allows you to index, transform, and use on-chain data at scale. By leveraging enriched on-chain data and streaming computing technologies across one data infrastructure, Chainbase automates the indexing and querying of blockchain data, enabling developers to accomplish more with less effort.

Want to learn more about Chainbase?

Visit our website chainbase.com Sign up for a free account, and Check out our documentation.

WebsiteBlogTwitterDiscordLink3

1
submitted 1 year ago by [email protected] to c/[email protected]

Table of Contents

  1. Introduction
  1. Tools Required for Working with Chainbase
  2. Set up a Free Account at Chainbase
  3. Write Script using Chainbase API
  4. Print Metadata of an ERC20 Token
  5. Conclusion
  6. FAQs

1. Introduction

If you're interested in automatically retrieving the metadata of ERC20 tokens, there's a convenient solution available: Chainbase API's getTokenMetadata. By utilizing this API, you can easily access the metadata of any ERC20 token by providing its contract address.

In this article, we will guide you through the process of obtaining ERC20 metadata using Chainbase API. We'll cover the tools required, setting up a free account at Chainbase, writing a script using our Chainbase API, and finally, printing the metadata of an ERC20 token.

2. Tools Required for Working with Chainbase

Before we dive into the process, make sure you have the following tools in place:

  1. A free account at Chainbase, along with an API key.
  2. An IDE (Integrated Development Environment) such as Visual Studio Code (VS Code) or any other of your choice.
  3. The contract address of the ERC20 token you want to retrieve metadata for.

Now that we have the necessary tools, let's proceed with the step-by-step instructions.

3. Set up a Free Account at Chainbase

To make the most of Chainbase's capabilities, start by creating a free account. Follow these steps:

  1. Visit the Chainbase website and log in to your account.
  2. Once logged in, navigate to the dashboard to get an overview of your account.
  3. Create a new project in the console.
  4. Obtain your API key, which will be required for making API requests.

4. Write Script using Chainbase API

Now that you have your Chainbase account set up, it's time to write a script using the Chainbase API. We'll demonstrate two examples using different JavaScript libraries: fetch and axios. Choose the one that suits your preference.

Example 1: Using fetch in JavaScript


network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
contract_addr = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'; // Take Matic Token's contract address as an example.

fetch(`https://api.chainbase.online/v1/token/metadata?chain_id=${network_id}&contract_address=${contract_addr}`, {
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
}).then(response => response.json())
    .then(data => console.log(data.data))
    .catch(error => console.error(error));

Example 2: Using axios in JavaScript You need to install axios using npm install axios --save in the terminal first.


network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
contract_addr = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'; // Take Matic Token's contract address as an example.

const axios = require('axios');
const options = {
    url: `https://api.chainbase.online/v1/token/metadata?chain_id=${network_id}&contract_address=${contract_addr}`,
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
};
axios(options)
    .then(response => console.log(response.data.data))
    .catch(error => console.log(error));

Choose the appropriate example and implement it in your preferred JavaScript environment.

5. Print Metadata of an ERC20 Token

The getTokenMetadata endpoint of the Chainbase API allows you to retrieve the metadata of an ERC20 token. It requires the chain ID and the token's contract address as parameters. Here's how you can print the metadata:

  1. Run the command node .js in your terminal, where `` corresponds to the file containing the script you wrote in Step 2.
  2. The returned data will include the contract address, token name, symbol, decimals, and total supply. An example of the data structure is as follows:

{
    "contract_address": "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0",
    "name": "Matic Token",
    "symbol": "MATIC",
    "decimals": 18,
    "total_supply": "0x204fce5e3e25026110000000"
}

Congratulations! You have successfully retrieved the metadata of the ERC20 token using Chainbase API.

6. Conclusion

In this article, we have explored how to obtain ERC20 metadata by contract using Chainbase API. We covered the necessary tools, setting up a free account at Chainbase, writing a script using Chainbase API, and printing the metadata of an ERC20 token. By following these steps, you can easily retrieve the metadata for any ERC20 token by providing its contract address.

Start leveraging Chainbase API's getTokenMetadata today and enhance your ERC20 token analysis and development process.

7. FAQs

1. Can I use Chainbase API with any ERC20 token?

Yes, you can use Chainbase API to get metadata for any ERC20 token by providing its contract address.

2. Do I need to pay for a Chainbase account?

No, Its free. We offers a free account with access to various APIs and data cloud services.

3. What programming language can I use with Chainbase API?

You can use any programming language that supports making HTTP requests. In our examples, we demonstrated JavaScript using the fetch and axios libraries.

4. How can I obtain my Chainbase API key?

Once you create a free account at Chainbase, you can obtain your API key from the account dashboard.

5. Are there any rate limits for using Chainbase API?

Yes, we do have rate limits to API requests. You can check the our documentation for specific details on rate limits and usage guidelines.


About Chainbase

Chainbase is an all-in-one data infrastructure for Web3 that allows you to index, transform, and use on-chain data at scale. By leveraging enriched on-chain data and streaming computing technologies across one data infrastructure, Chainbase automates the indexing and querying of blockchain data, enabling developers to accomplish more with less effort.

Want to learn more about Chainbase?

Visit our website chainbase.com Sign up for a free account, and Check out our documentation.

WebsiteBlogTwitterDiscordLink3

0
submitted 1 year ago by [email protected] to c/[email protected]

Overview - Tools you need to work with Chainbase

To automatically retrieve all the transfers of an ERC20 token using its contract address, you can utilize Chainbase API's getTokenTransfers function. This article will guide you through the necessary steps to achieve this.

Outline of the Article

  1. Introduction
  1. Setting up a free account at Chainbase
  2. Writing a script using Chainbase API
  3. Printing metadata of an ERC20 token
  4. API Reference
  5. Support
  6. Conclusion
  7. FAQs

1. Introduction

When working with ERC20 tokens, it can be beneficial to track and analyze the token transfers associated with a specific contract address. Chainbase API offers a convenient solution to retrieve all the transfers of an ERC20 token efficiently.

2. Setting up a free account at Chainbase

To fully leverage the capabilities of Chainbase api, you need to create a free account on our platform. Follow these steps:

  • Visit the Chainbase website and sign up for a free account.
  • Once logged in, navigate to the dashboard to get an overview of the available features.
  • Create a new project in the console to obtain an API key.

3**. Writing a script using Chainbase API**

To retrieve all the transfers of an ERC20 token, you can use the Chainbase API in your script. Here are examples of how to accomplish this in JavaScript:

Using fetch:

network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
contract_addr = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'; // Take Matic Token's contract address as an example.

fetch(`https://api.chainbase.online/v1/token/transfers?chain_id=${network_id}&contract_address=${contract_addr}&page=1&limit=5`, {
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
}).then(response => response.json())
    .then(data => console.log(data.data))
    .catch(error => console.error(error));

Using axios:

You need to install axios using npm install axios --save in the terminal first.

network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
contract_addr = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'; // Take Matic Token's contract address as an example.

const axios = require('axios');
const options = {
    url: `https://api.chainbase.online/v1/token/transfers?chain_id=${network_id}&contract_address=${contract_addr}&page=1&limit=5`,
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
};
axios(options)
    .then(response => console.log(response.data.data))
    .catch(error => console.log(error));

4**. Printing metadata of an ERC20 token**

By using the Chainbase API's getTokenTransfers function with the appropriate parameters, you can obtain the transfers related to a specific ERC20 token. Additionally, if you provide an address, you can filter the transfers to a specific address. The returned data will include information such as block number, timestamp, addresses involved, transaction hash, transaction index, transaction fee, and transfer value.

To get data printed, run command node .js in the terminal. In this case, the data returned looks as follows.

{
  "block_number": 17182749,
  "block_timestamp": "2023-05-03T21:06:23Z",
  "from_address": "0x25feaf3f5f36b44d0cb5a9c735d205e66f94437c",
  "log_index": 292,
  "to_address": "0xa3fd5a303020f2eeee79d9fc4ae468bca6bccc56",
  "transaction_hash": "0x443b17a0ea6418b4b0e467dd7c495034bf13c2be65dc8fca958f4a8ec7c53513",
  "transaction_index": 137,
  "tx_fee": 3918874072581520,
  "tx_type": 2,
  "value": "188992828092557071964"
},
{
  "block_number": 17182747,
  "block_timestamp": "2023-05-03T21:05:59Z",
  "from_address": "0x0979850acd0133fbf330e3d2f2540e111b77e969",
  "log_index": 329,
  "to_address": "0x1522900b6dafac587d499a862861c0869be6e428",
  "transaction_hash": "0xf1208710548fe0ac4ad9d6e3a2157adc741f8eeca0914d2cb680a18cb7ac42fd",
  "transaction_index": 139,
  "tx_fee": 4530117915638504,
  "tx_type": 2,
  "value": "2178406783020000000000"
},
{
  "block_number": 17182742,
  "block_timestamp": "2023-05-03T21:04:59Z",
  "from_address": "0xd9a506404e71e1f461a1d532a1f748aa1a52c437",
  "log_index": 259,
  "to_address": "0x51a9f80cdfe9c6996d95e5f6b6d029ed7ddd5001",
  "transaction_hash": "0x0d823b7261b741474d7635913abc315c4f188756b0e793b2eb5276f463efcb63",
  "transaction_index": 95,
  "tx_fee": 4091630857640924,
  "tx_type": 2,
  "value": "419123260000000000000"
},
{
  "block_number": 17182734,
  "block_timestamp": "2023-05-03T21:03:11Z",
  "from_address": "0x21a31ee1afc51d94c2efccaa2092ad1028285549",
  "log_index": 169,
  "to_address": "0x0979850acd0133fbf330e3d2f2540e111b77e969",
  "transaction_hash": "0x5b08286a38964c59925019f1f57b9b49270481cc97875bcc866d3eadb1f6a5cc",
  "transaction_index": 66,
  "tx_fee": 4178649496106592,
  "tx_type": 2,
  "value": "2178406783020000000000"
},
{
  "block_number": 17182733,
  "block_timestamp": "2023-05-03T21:02:59Z",
  "from_address": "0x28c6c06298d514db089934071355e5743bf21d60",
  "log_index": 216,
  "to_address": "0xf23500fec72b26535a2d61383a665439919f287f",
  "transaction_hash": "0xa135997a18e3aa2413b1e2cf262db44fa0418758c57dc0b5b1e8456fcedfba32",
  "transaction_index": 72,
  "tx_fee": 4095379462808136,
  "tx_type": 2,
  "value": "4133504000000000000000"
}

5**. API Reference**

If you want to know more details on the endpoint and optional parameters, check out:

6**. Support**

If you encounter any difficulties while following this tutorial, don't hesitate to reach out to our Chainbase community support on the Discord server. They provide 24/7 assistance and guidance.

7. Conclusion

In conclusion, retrieving all ERC20 transfers by contract address becomes effortless with the help of our Chainbase API. By setting up an account, writing a script using the API, and utilizing the getTokenTransfers function, you can access and analyze valuable transfer data for ERC20 tokens.

8. FAQs

Q1: Can I retrieve transfers from multiple ERC20 tokens using Chainbase API?

A1: Yes, you can retrieve transfers for any ERC20 token by providing its contract address as a parameter to the getTokenTransfers function.

Q2: Is the Chainbase API free to use?

A2: We offer a free account plan that gives you access to the API. We also have paid plans available for more advanced features and higher usage limits. You can find more information on our pricing page.

Q3: Can I filter transfers by a specific address using Chainbase API?

A3: Yes, you can specify an address in the request to filter transfers related to that specific address.

Q4: How frequently is the transfer data updated in Chainbase?

A4: The transfer data is typically updated in real-time or with a minimal delay, depending on the blockchain network's performance.

Q5: Can I integrate Chainbase API into my own application or project?

A5: Absolutely! Our Chainbase API is designed to be integrated into various applications, projects, and services that require access to ERC20 transfer data.


About Chainbase

Chainbase is an all-in-one data infrastructure for Web3 that allows you to index, transform, and use on-chain data at scale. By leveraging enriched on-chain data and streaming computing technologies across one data infrastructure, Chainbase automates the indexing and querying of blockchain data, enabling developers to accomplish more with less effort.

Want to learn more about Chainbase?

Visit our website chainbase.com Sign up for a free account, and Check out our documentation.

WebsiteBlogTwitterDiscordLink3

-2
submitted 1 year ago by [email protected] to c/[email protected]

Welcome to another Chainbase tutorial! In this guide, we'll explore how to retrieve PancakeSwap trading data using GraphQL. PancakeSwap is a popular decentralized exchange on the Binance Smart Chain, and understanding its trading data is essential for both developers and traders.

Introduction

PancakeSwap offers various ways to trade, earn, and win with crypto. With its rich set of trading data, developers can create applications, analytics tools, and more. In this tutorial, we'll focus on how to retrieve this data using GraphQL queries.

Prerequisites

  • Familiarity with GraphQL.
  • A free account at Chainbase with an API key.

Explore Chainbase Datasets

Before diving into the queries, we encourage you to explore Chainbase Datasets. Here you'll find a wide range of blockchain datasets, tools, and insights that can enhance your development and analysis process. Whether you're a developer, researcher, or trader, Chainbase Datasets provide valuable resources to support your work

Retrieve Transaction Information

Query

query TxInfo($hash: String) {
  transactions(orderBy: timestamp, orderDirection: desc, where: {id: $hash}) {
    id
    timestamp
    block
    swaps(orderBy: timestamp, orderDirection: desc) {
      from
      to
      amountUSD
    }
  }
}

Example

{
  "hash": "0xd856754ded011e5fce3b7c01fce179c34f92fd3bfcd86c5f2b528f1627f45b6e"
}

This query retrieves the transaction details by the given hash, including timestamp, block, and swap information.

Get Swaps Information

Query

query GetSwaps {
  swaps(
    orderBy: timestamp
    orderDirection: desc
    first: 3
  ) {
    id
    to
    from
    amount0In
    amount0Out
    token0 {
      symbol
      totalLiquidity
      tradeVolume
      tradeVolumeUSD
    }
    token1 {
      symbol
      totalTransactions
      tradeVolume
      tradeVolumeUSD
    }
  }
}

This query returns the latest three swaps, including details about the tokens involved.

Access Daily Data

Query

query DayData {
  pancakeDayDatas(first: 10, orderBy: date, orderDirection: desc) {
    date
    id
    dailyVolumeUSD
    totalLiquidityUSD
    totalVolumeUSD
  }
}

This query provides the last 10 days of data, including daily volume in USD, total liquidity in USD, and total volume in USD.

Retrieve Pair Daily Information

Query

query MyQuery($pairAddress: String!) {
  pairDayDatas(where: {pairAddress: $pairAddress}) {
    id
    dailyTxns
    dailyVolumeUSD
    pairAddress
  }
}

Example

{
"pairAddress":"0x0040b189602d76a83ab40646cbe8d71430a07a5e"
}

This query retrieves daily transaction data for the specified pair address.

Conclusion

Retrieving PancakeSwap trading data with GraphQL is a powerful and efficient method. This tutorial provides a step-by-step guide to help you access and analyze this data, opening up new possibilities for building applications and understanding the PancakeSwap ecosystem.

Chainbase continues to support the blockchain community with tutorials, datasets, and tools. Stay tuned for more insights and guides!

For more information about PancakeSwap and its features, you can visit the official website. For more tutorials and insights, explore the Chainbase blog.

Happy trading and building!

FAQ

Q1: Can I use GraphQL with other decentralized exchanges?

A: Yes, GraphQL is a query language that can be used with many other decentralized exchanges that offer similar APIs.

Q2: How do I get my API key from Chainbase?

A: You can sign up for a free account at Chainbase and obtain an API key from the account settings.

Q3: Can I retrieve more than 10 days of trading data?

A: Yes, you can modify the query to retrieve data for a different number of days as per your requirement.

Q4: Is PancakeSwap only available on the Binance Smart Chain?

A: Yes, PancakeSwap operates on the Binance Smart Chain.

Q5: Where can I learn more about PancakeSwap?

A: You can visit the official PancakeSwap website and explore the platform's detailed documentation and community forums.

About Chainbase

Chainbase is an all-in-one data infrastructure for Web3 that allows you to index, transform, and use on-chain data at scale. By leveraging enriched on-chain data and streaming computing technologies across one data infrastructure, Chainbase automates the indexing and querying of blockchain data, enabling developers to accomplish more with less effort.

Want to learn more about Chainbase?

Visit our website chainbase.com Sign up for a free account, and Check out our documentation.

WebsiteBlogTwitterDiscordLink3

3
submitted 1 year ago by [email protected] to c/[email protected]

Introduction

In this tutorial, we'll be using the Chainbase DeFi dataset to retrieve the addresses of Uniswap V2 pools. Chainbase provides a wealth of blockchain data, enabling developers to access, analyze, and utilize on-chain data easily and efficiently.

Prerequisites

  1. A free account at Chainbase with an API key.
  2. An IDE. Our examples are shown in JavaScript, you can use VS Code as your IDE for example.
  3. A contract address of an ERC20 token as your input.

Register and Get API Key

To begin with, you'll need to register on Chainbase and obtain an API key. This key will be used to authenticate your requests to the Chainbase API.

Retrieve Pool Data Via Chainbase Dataset

In this section, we will learn how to retrieve pool data from the Chainbase dataset. Let's use the following query:


query SpecificTokenInfo {
  liquidityPool(id: "0xd6e3f90f531f8dc9229ddbd2e59b4a6c7a5f5de0") {
    inputTokens {
      symbol
      id
      decimals
    }
    outputToken {
      symbol
      id
      decimals
    }
  }
}

This query allows us to obtain information about a specific liquidity pool by providing its ID. The response will include details about the input and output tokens, such as their symbols, IDs, and decimals.

Get Pool Information with Pagination

Now, let's explore how to get pool information using pagination. The following query demonstrates this:

query GetPoolInfo($inputTokens: String, $skip: Int!) {
  liquidityPools(
    first: 100
    skip: $skip
    orderBy: createdTimestamp
    where: {inputTokens_: {name: $inputTokens}}
  ) {
    createdTimestamp
    deposits {
      hash
      _walletAddress
    }
  }
}

#eg.
{
  "inputTokens": "USDT",
  "skip": 2
}

This query enables us to retrieve pool information in batches of 100 pools at a time, skipping the desired number of pools using the $skip variable. The pools are ordered by their creation timestamp, and we can filter the results based on the input tokens' name.

Query Withdraw and Deposit Information

To query the withdraw and deposit information from a specific address, we can use the following query:

# Query the withdraw and deposit information from a specific address
query GetWallet($wallet: String) {
withdraws(where: {from: $wallet}) {
	blockNumber
	from
	hash
	id
	logIndex
	timestamp
	to
}
deposits(where: {from: $wallet}) {
	blockNumber
	from
	hash
	id
	logIndex
	timestamp
	to
	}
}

# eg.
{
  "wallet": "0xb862cd7c725139bbed253bbc7f06e359a89bdea7"
}

By providing the wallet address through the $wallet variable, we can obtain details about both withdrawals and deposits associated with that address.

Query Pool Transactions

Lastly, let's explore how to query pool transactions. The following query accomplishes this:

query GetPoolTx {
  liquidityPools(
    first: 5,
    orderBy: createdTimestamp, 
    orderDirection: desc) {
    createdTimestamp
    deposits {
      id
      _walletAddress
      from
      to
      inputTokenAmounts
      inputTokens {
        symbol
      }
      outputTokenAmount
      outputToken {
        symbol
      }
    }
    swaps {
      id
      _walletAddress
      from
      to
    }
    withdraws {
      id
      _walletAddress
      from
      to
    }
  }
}

This query fetches data for the five most recent liquidity pools. It includes details about deposits, swaps, and withdrawals associated with these pools.

Using the GraphQL Query UniV2Pool

The GraphQL query UniV2Pool allows us to retrieve specific information about the top Uniswap V2 liquidity pools. Let's dive into the details of the query:

query UniV2Pool {
  liquidityPools(first: 5, orderBy: createdTimestamp, orderDirection: desc) {
    id
    name
    createdBlockNumber
    inputTokens {
      symbol
    }
    swaps(orderBy: timestamp, orderDirection: desc) {
      hash
      amountIn
      amountOut
    }
  }
}

In this query, we are using the liquidityPools field to fetch data for the first five pools. The pools are sorted based on their creation timestamp in descending order, meaning we get the most recently created pools first.

Results

"liquidityPools": [
      {
        "id": "0xd6e3f90f531f8dc9229ddbd2e59b4a6c7a5f5de0",
        "name": "Uniswap V2 Worldcoin/Wrapped Ether",
        "createdBlockNumber": "17761399",
        "inputTokens": [
          {
            "symbol": "WLD"
          },
          {
            "symbol": "WETH"
          }
        ],
        "swaps": []
      },
      {
        "id": "0x26bdfc68454a5028de4109007c8e2f6cbf0af33f",
        "name": "Uniswap V2 TAGToken/Wrapped Ether",
        "createdBlockNumber": "17761364",
        "inputTokens": [
          {
            "symbol": "TAG"
          },
          {
            "symbol": "WETH"
          }
        ],
        "swaps": []
      },
      {
        "id": "0x50a516b47e4a3da12bced268645baa1da34b25b5",
        "name": "Uniswap V2 X.com/Wrapped Ether",
        "createdBlockNumber": "17761362",
        "inputTokens": [
          {
            "symbol": "X.com"
          },
          {
            "symbol": "WETH"
          }
        ],

Conclusion

In conclusion, using our DeFi dataset to retrieve Uniswap V2 pool addresses is a powerful tool for blockchain developers. By following the provided queries and steps, you can efficiently access and analyze on-chain data. Chainbase opens up new possibilities for building DeFi applications and understanding blockchain ecosystems.

FAQs

  1. What is Chainbase? Chainbase is a platform that provides a comprehensive set of blockchain data, allowing developers to access and utilize on-chain information for their projects.
  2. Why do I need an API key for Chainbase? The API key serves as a security measure to authenticate your requests and ensure that only authorized users can access Chainbase's data.
  3. Can I use other programming languages instead of JavaScript for the examples? Yes, you can use other programming languages that are compatible with the Chainbase API, but the examples in this tutorial are demonstrated in JavaScript.
  4. How does pagination help in retrieving pool information? Pagination breaks down the data retrieval into smaller, manageable chunks. It allows you to retrieve a limited number of pools at a time, making the process more efficient.
  5. What data can I obtain from querying pool transactions? By querying pool transactions, you can get valuable information about deposits, swaps, and withdrawals associated with specific liquidity pools.

About Chainbase

Chainbase is an all-in-one data infrastructure for Web3 that allows you to index, transform, and use on-chain data at scale. By leveraging enriched on-chain data and streaming computing technologies across one data infrastructure, Chainbase automates the indexing and querying of blockchain data, enabling developers to accomplish more with less effort.

Want to learn more about Chainbase?

Visit our website chainbase.com Sign up for a free account, and Check out our documentation.

WebsiteBlogTwitterDiscordLink3

view more: next ›

Chainbaseintern

joined 1 year ago