# Json Web Token(JWT) Source: https://docs.chainbase.com/api-reference/jtw ## What is a JWT? JSON Web Tokens (JWTs), also known as JOTs, were created to establish a standard and secure method for two parties to communicate. They offer the advantage of stateless session management, eliminating the need for communication between a backend server and an authorization server. JWTs can be transmitted via an HTTP header, URL, or POST parameter, and their compact size contributes to their efficiency. A JWT comprises three parts: a **Header**, **Payload**, and **Signature**, each separated by a period and derived from a JSON object that is encoded into a text string using BASE64. Further information on this standard is available in [RFC-7519](https://tools.ietf.org/html/rfc7519). ## How to use JWT in Chainbase? Chainbase now provides users with the option to safeguard their blockchain nodes using the JWT authentication method. This feature can be utilized either as a stand-alone security measure or in conjunction with other protective methods offered by Chainbase, including IP whitelisting and domain whitelisting. It should be noted that if multiple authentication services are activated on a project, each method must successfully pass its security check, or the user request will result in an error. ### Generate your RSA-256 keys Chainbase supports JWTs created from key pairs using the **RS256** algorithm. Generate your own **RSA-256** public and private key with 2048 length. Below is the example using OpenSSL. ```bash # generate rsa key openssl genrsa -out jwtRSA256-private.pem 2048 openssl rsa -in jwtRSA256-private.pem -pubout -outform PEM -out jwtRSA256-public.pem ``` ### Add public key to a Chainbase Project Step 1: Login -> Dashboard -> Choose a project -> Security (tab) Step 2: Click "Add" button and Input the public key generated in the previous step. Step 3: You will obtain the public key ID after clicking "Create" button. ### Enable JWT feature After enabling the JWT feature, it is mandatory to include the JWT in the header of all subsequent requests. ### Generate the JWT To generate a JWT, the following components are required: **Header**, **Payload**, and **Signature**. An example of how to generate a JWT using [https://jwt.io/](https://jwt.io/) is provided below. Step 1: Choose **RS256** algorithm Step 2: Paste the following JSON to the JWT tool to encode the **Header** component. ```json { "alg": "RS256", "typ": "JWT", "kid": "e7af4467-00f1-480e-97d7-6490d7f749b9" } ``` Here are the meanings of the fields: | Field | Description | Example | | :---- | :------------------------------- | :------ | | alg | The signing algorithm being used | RS256 | | typ | The type of the token | JWT | | kid | The key id copied from Chainbase | XXX | Step 3: Paste the following JSON to the JWT tool to encode the **Payload** component. ```json { "aud": "chainbase.com", "exp": 1690523501 } ``` Here are the meanings of the fields: | Field | Description | Example | | :---- | :-------------------------------------- | :------------ | | aud | The audience of this JWT | chainbase.com | | exp | The expiry time. Unix timestamp format. | 1690523501 | Step 4: Input your private key to generate the **Signature** component. Congrats! Now you get the encoded JWT. You can verify your token by providing your public key to the JWT debugger. ### Send requests with JWT After generating the JWT, you would need to add the JWT as a part of your request header `-H "Authorization: Bearer` entry. ```bash curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ --data '{"jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber", "params": []}' \ "https://ethereum-mainnet.s.chainbase.online/v1/" ``` In the event that the JWT feature has been activated but requests are sent without a JWT or with an invalid JWT, an HTTP **401** error status code will be returned along with the following response. ## FAQ > Q: Which APIs are JWT supported on? > > A: JWT is supported on all Chainbase API services. > Q: How do I discard a JWT before it expires? > > A: If your JWT might have been exposed and you want to prevent it from being used, you can remove the public key from the security tab. > Q: Can I add multiple JWTs to a project? > > A: Yes. If multiple JWTs are active, the request should only match one of the available keys to succeed. Chainbase now supports up to 3 keys. > Q: Which cipher does Chanbase support? > > A: RSA 256 (RS256) is supported at this time. > Q: What expiration date should I choose? > > A: You can set any expiration date in the future you'd like. Generally, the shorter the expiration time, the more secure your JWT is. # Overview Source: https://docs.chainbase.com/api-reference/overview 📘 Don’t have an API key? Go to [console.chainbase.com](https://console.chainbase.com/) to create an account and a new API key. For demo purposes, you can use the key "demo" to test out the API. ## Web3 API Web3 API is a suite of **REST** and **Stream** APIs that simplify your web3 development process with seamless access to on-chain and off-chain data. No matter what you're building, our Web3 API will provide the necessary data support, including balance, transaction history, ownership, and price information. ## Advanced API Suite ## Chain RPC The Chain API easily connects your dApp to a node that is part of the blockchain network. Developers can interact with on-chain data and send different types of transactions to the network by utilizing the endpoints provided by Chainbase ### EVM Compatible ### Non-EVM Compatible # Data Cloud SQL Query (Classic) Source: https://docs.chainbase.com/api-reference/sql-api/data-cloud-sql-query post /dw/query ## Example Query the hashes of the last 3,000 blocks in Ethereum and the number of transactions in each block: ```bash curl -X "POST" "https://api.chainbase.online/v1/dw/query" \ -H 'X-API-KEY: YOUR-API-KEY ' \ -H 'Content-Type: application/json; charset=utf-8' \ -d $'{ "query": "select number, transactions_count from ethereum.blocks order by number desc limit 3000;" }' ``` If there are more than 1000 rows, you need to paginate through the`task_id` and `page` to get all the results: ```bash curl -X "POST" "https://api.chainbase.online/v1/dw/query" \ -H 'X-API-KEY: YOUR-API-KEY ' \ -H 'Content-Type: application/json; charset=utf-8' \ -d $'{ "task_id": "xxxxxxxxxxxxxxxxxxxxx", "page": 2 }' ``` 🚧 Note 1. When `quey_id` is passed in, the content of query will be ignored 2. The executed request generates a `task_id`, which is valid for 1 hour 3. A maximum of 100,000 pieces of data are allowed to be obtained from the request, and 1,000 results are paginated per page # Execute Queries (Alpha) Source: https://docs.chainbase.com/api-reference/sql-api/execute-queries post /query/execute Limit of 100,000 results # Get Query Results (Alpha) Source: https://docs.chainbase.com/api-reference/sql-api/get-query-results get /execution/{execution_id}/results # Get Query Status (Alpha) Source: https://docs.chainbase.com/api-reference/sql-api/get-query-status get /execution/{execution_id}/status # API Status Code Source: https://docs.chainbase.com/api-reference/status-code ## JSON-RPC API | Status Code | Description | Message | | :---------- | :----------------------------------------------------------------------------------------------------------------------- | :----------------------------------------- | | -32000 | Error code flag for backward compatibility. | Something happened, Please try again Later | | -32600 | This is an invalid request, check the request package. | Invalid Request | | -32601 | The corresponding method is not found. You need to check whether this is the interface supported by the client standard. | Method not found | | -32602 | This method uses the wrong parameter. (Check to see if the parameter is forgotten or too many.) | Invalid params | | -32603 | There may be a network voice fault. Try again later. | Internal error | | -32700 | The parsing process sounds an error. | Parse error | ## HTTP API | Status Code | Message | Description | | :----------------- | :---------------- | :------------------------------------------------------------------------------------------------------ | | 200 | OK | Everything worked as expected. | | 400 | Bad Request | The request was unacceptable, often due to missing a required parameter. | | 401 | Unauthorized | The request requires authentication. After logging in, the server may return this response to the page. | | 402 | Request Failed | The parameters were valid but the request failed. | | 403 | Forbidden | The server rejects the request. | | 404 | Not Found | The requested resource doesn't exist. | | 429 | Too Many Requests | Too many requests hit the API request rate limit. | | 500, 502, 503, 504 | Server Errors | Something went wrong on Chainbase's end. (These are rare.) | # Get NFTs owned by address Source: https://docs.chainbase.com/api-reference/web3-api/balance/nft-balances/get-nfts-owned-by-address get /v1/account/nfts Get the list of NFTs owned by an account. # Get ERC20 token balances Source: https://docs.chainbase.com/api-reference/web3-api/balance/token-balances/get-erc20-token-balances get /v1/account/tokens Retrieve all token balances for all ERC20 tokens for a specified address. By default, it will return all token balances for all ERC20 tokens that the address has ever received. You can specify a contract address to check the balance of a non-standard contract. # Get native token balances Source: https://docs.chainbase.com/api-reference/web3-api/balance/token-balances/get-native-token-balances get /v1/account/balance Returns the balance for a specified address. # Get block by number Source: https://docs.chainbase.com/api-reference/web3-api/basic/block/get-block-by-number get /v1/block/detail Get the detail of a block by the given block number. # Get latest block number Source: https://docs.chainbase.com/api-reference/web3-api/basic/block/get-latest-block-number get /v1/block/number/latest Get the latest block height of blockchain network. # Contract call Source: https://docs.chainbase.com/api-reference/web3-api/basic/contract/contract-call post /v1/contract/call Calls a specific function for the specified contract. # Address labels Source: https://docs.chainbase.com/api-reference/web3-api/basic/labels/get-address-labels get /v1/address/labels get labels by address # Get transaction Source: https://docs.chainbase.com/api-reference/web3-api/basic/transaction/get-transaction get /v1/tx/detail Get the detail of a transaction given the transaction hash. Provide the param "hash" or ("block_number" and "tx_index"). If both params are provided, "hash" will be used. # Get transactions by account Source: https://docs.chainbase.com/api-reference/web3-api/basic/transaction/get-transactions-by-account get /v1/account/txs Returns the transactions from the address. # Get ENS domains Source: https://docs.chainbase.com/api-reference/web3-api/domain/ens-domain-endpoints/get-ens-domains get /v1/account/ens Gets a list of ENS domains held by a given address. # Resolve ENS domain Source: https://docs.chainbase.com/api-reference/web3-api/domain/ens-domain-endpoints/resolve-ens-domain get /v1/ens/records Resolves a ETH address given an ENS Domain. # Reverse resolve ENS domain Source: https://docs.chainbase.com/api-reference/web3-api/domain/ens-domain-endpoints/reverse-resolve-ens-domain get /v1/ens/reverse Reverse resolves a given ETH address to its ENS domain. # Get NFT collection items Source: https://docs.chainbase.com/api-reference/web3-api/nft/nft-collections/get-nft-collection-items get /v1/nft/collection/items Query NFT collection items metadata. # Get NFT collection metadata Source: https://docs.chainbase.com/api-reference/web3-api/nft/nft-collections/get-nft-collection-metadata get /v1/nft/collection Query NFT collection metadata. # Get NFT metadata Source: https://docs.chainbase.com/api-reference/web3-api/nft/nft-metadata/get-nft-metadata get /v1/nft/metadata Get the metadata associated with the specified NFT. # Get NFT rarity Source: https://docs.chainbase.com/api-reference/web3-api/nft/nft-metadata/get-nft-rarity get /v1/nft/rarity # Get NFT owner by token Source: https://docs.chainbase.com/api-reference/web3-api/nft/nft-ownership/get-nft-owner-by-token get /v1/nft/owner Get the current owner for a specified NFT token. # Get NFT owner history by token Source: https://docs.chainbase.com/api-reference/web3-api/nft/nft-ownership/get-nft-owner-history-by-token get /v1/nft/owner/history Get the list of historical owner addresses for a specified NFT token. # Get NFT owners by collection Source: https://docs.chainbase.com/api-reference/web3-api/nft/nft-ownership/get-nft-owners-by-collection get /v1/nft/owners Get all owners for a specified NFT collection. # Get NFT transfers by collection Source: https://docs.chainbase.com/api-reference/web3-api/nft/nft-transfers/get-nft-transfers-by-collection get /v1/nft/transfers Get the historical transfer transactions for a specified contract address. # Get token price Source: https://docs.chainbase.com/api-reference/web3-api/token/market-data/get-token-price get /v1/token/price Get the price of the specified token. # Get token price history Source: https://docs.chainbase.com/api-reference/web3-api/token/market-data/get-token-price-history get /v1/token/price/history Get the historical price of the specified token. # Get token holders Source: https://docs.chainbase.com/api-reference/web3-api/token/token-holders/get-token-holders get /v1/token/holders Get the list of holders of the specified contract. # Get top token holders Source: https://docs.chainbase.com/api-reference/web3-api/token/token-holders/get-top-token-holders get /v1/token/top-holders Get the list of top holders of the specified contract. # Get token metadata Source: https://docs.chainbase.com/api-reference/web3-api/token/token-metadata/get-token-metadata get /v1/token/metadata Get the metadata of a specified token. # Get token transfers by contract Source: https://docs.chainbase.com/api-reference/web3-api/token/token-transfers/get-token-transfers-by-contract get /v1/token/transfers Retrieves historical token transfer transactions for any ERC20 contract. # Abstracted Source: https://docs.chainbase.com/catalog/Arbitrum/Abstracted ## 1.arbitrum.token\_metas ### Table Description Token metadata in the context of blockchain and cryptocurrencies typically refers to the set of data that describes the characteristics and details of a particular token. This metadata can include information such as the token's name, symbol, total supply, decimal precision, and other details relevant to its function and identity on the blockchain. It's essentially the descriptive data that gives context and identity to a token, distinguishing it from other tokens within the same blockchain ecosystem. Metadata is crucial for understanding the nature and purpose of a token, especially in applications like wallets, exchanges, and decentralized applications (dApps) where users interact with various types of tokens. ### Column Descriptions