├── .env.sample ├── .gitattributes ├── src ├── config │ └── config.js ├── utils │ ├── security.js │ ├── validation.js │ ├── pricing.js │ ├── balances.js │ ├── base.js │ ├── transactions.js │ └── nft.js └── index.js ├── package.json ├── index.js ├── .gitignore ├── README.md └── LICENSE /.env.sample: -------------------------------------------------------------------------------- 1 | CHAINSTACK_API_KEY="YOUR_API_KEY" -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /src/config/config.js: -------------------------------------------------------------------------------- 1 | // API URLs config 2 | 3 | module.exports = { 4 | COVALENT_BASE_URL: 'https://api.covalenthq.com/v1', 5 | API_BASE_URL: 'https://api.chainstack.com/v1', 6 | }; 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chainstack-covalent-sdk", 3 | "version": "1.0.8", 4 | "description": "An SDK designed to streamline the process of developing using the integration of Chainstack with Covalent APIs, enhancing the ease of use and efficiency", 5 | "main": "./src/index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "chainstack", 11 | "covalent", 12 | "api", 13 | "blockchain" 14 | ], 15 | "author": "DZ", 16 | "license": "Apache-2.0", 17 | "dependencies": { 18 | "axios": "^1.4.0", 19 | "dotenv": "^16.0.3" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/utils/security.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | const { COVALENT_BASE_URL } = require('../config/config'); 3 | 4 | module.exports = function(ChainstackApi) { 5 | ChainstackApi.prototype.getTokenApprovalsForAddress = async function({ chainName, walletAddress }) { 6 | try { 7 | const validatedToken = await this.validateToken(); 8 | 9 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/approvals/${walletAddress}/`); 10 | 11 | const response = await axios.get(url, { 12 | headers: { 13 | 'Authorization': `Bearer ${validatedToken}` 14 | } 15 | }); 16 | 17 | return response.data; 18 | } catch (error) { 19 | console.error('Error getting token approvals for address:', walletAddress, 'on chain:', chainName, 'Error:', error); 20 | throw new Error(`Failed to get token approvals for address ${walletAddress} on chain ${chainName}: ${error.message}`); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/utils/validation.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | require('dotenv').config(); 3 | const { API_BASE_URL } = require('../config/config'); 4 | /** 5 | * This function validates the API key by making a POST request to the Chainstack API. 6 | * @param {string} key - The API key to be validated. 7 | * @returns {Promise} - The response data from the Chainstack API. 8 | * @throws {Error} - Throws an error if the POST request fails. 9 | */ 10 | async function validateApiKey(key) { 11 | try { 12 | const response = await axios.post( 13 | `${API_BASE_URL}/marketplace/applications/covalent/token/`, 14 | {}, 15 | { 16 | headers: { 17 | 'Authorization': `Bearer ${key}`, 18 | }, 19 | } 20 | ); 21 | return response.data; 22 | } catch (error) { 23 | console.error('An error occurred while validating the API key:', error); 24 | throw error; 25 | } 26 | } 27 | 28 | // Export the validation function 29 | module.exports = { 30 | validateApiKey, 31 | }; 32 | -------------------------------------------------------------------------------- /src/utils/pricing.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | const { COVALENT_BASE_URL } = require('../config/config'); 3 | 4 | module.exports = function(ChainstackApi) { 5 | ChainstackApi.prototype.getHistoricalTokenPrices = async function({ chainName, quoteCurrency="USD", contractAddress, from, to, pricesAtAsc=false }) { 6 | try { 7 | const validatedToken = await this.validateToken(); 8 | 9 | const url = new URL(`${COVALENT_BASE_URL}/pricing/historical_by_addresses_v2/${chainName}/${quoteCurrency}/${contractAddress}/`); 10 | const params = { 11 | from: from, 12 | to: to, 13 | 'prices-at-asc': pricesAtAsc 14 | }; 15 | url.search = new URLSearchParams(params).toString(); 16 | 17 | const response = await axios.get(url, { 18 | headers: { 19 | 'Authorization': `Bearer ${validatedToken}` 20 | } 21 | }); 22 | 23 | return response.data; 24 | } catch (error) { 25 | console.error('Error fetching historical token prices for contract address:', contractAddress, 'on chain:', chainName, 'Error:', error); 26 | throw new Error(`Failed to fetch historical token prices for contract address ${contractAddress} on chain ${chainName}: ${error.message}`); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | require('dotenv').config(); 3 | 4 | const { COVALENT_BASE_URL } = require('../src/config/config'); 5 | const {validateApiKey} = require('./utils/validation') 6 | 7 | class ChainstackApi { 8 | constructor(key) { 9 | this.apiKey = key; 10 | this.tokenCache = {}; 11 | } 12 | 13 | async validateToken() { 14 | // check for base covalent 15 | const regex = /^cqt_r[A-Za-z0-9]{27}$/; 16 | if (regex.test(this.apiKey)){ 17 | return this.apiKey; 18 | } 19 | 20 | const cachedToken = this.tokenCache[this.apiKey]; 21 | const oneHour = 55 * 60 * 1000; // in milliseconds 22 | 23 | if (cachedToken && (Date.now() - cachedToken.timestamp < oneHour)) { 24 | return cachedToken.token; 25 | } 26 | 27 | try { 28 | const response = await validateApiKey(this.apiKey); 29 | this.tokenCache[this.apiKey] = { token: response.access_token, timestamp: Date.now() }; 30 | return response.access_token; 31 | } catch (error) { 32 | console.error('Error validating token:', error); 33 | throw new Error(`Failed to validate API key ${this.apiKey}: ${error.message}`); 34 | } 35 | } 36 | } 37 | 38 | require('./utils/balances')(ChainstackApi); 39 | require('./utils/nft')(ChainstackApi); 40 | require('./utils/transactions')(ChainstackApi); 41 | require('./utils/security')(ChainstackApi); 42 | require('./utils/base')(ChainstackApi); 43 | require('./utils/pricing')(ChainstackApi); 44 | 45 | module.exports.ChainstackApi = ChainstackApi; 46 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { ChainstackApi } = require('./src/index'); 2 | 3 | const CHAINSTACK_API_KEY = process.env.CHAINSTACK_API_KEY 4 | const chainstack = new ChainstackApi(CHAINSTACK_API_KEY); 5 | 6 | const commonConfig = { 7 | chainName: 'eth-mainnet', 8 | walletAddress: '0x45794810982d2024901a0972ee101ACfBc018E0B', 9 | }; 10 | 11 | const fetchTokenBalancesConfig = { 12 | ...commonConfig, 13 | currency: 'USD', 14 | nft: true, 15 | noNftFetch: false, 16 | noSpam: true, 17 | }; 18 | 19 | const fetchTransactionsConfig = { 20 | ...commonConfig, 21 | currency: 'USD', 22 | noLogs: true, 23 | }; 24 | 25 | const getAllTransactionsInBlockConfig = { 26 | ...commonConfig, 27 | blockHeight: 100, 28 | quoteCurrency: 'USD', 29 | noLogs: true, 30 | }; 31 | 32 | const getBulkTimeBucketTransactionsConfig = { 33 | ...commonConfig, 34 | timeBucket: 100, 35 | quoteCurrency: 'USD', 36 | noLogs: true, 37 | }; 38 | 39 | const functionsConfigMap = { 40 | fetchTokenBalances: fetchTokenBalancesConfig, 41 | fetchNfts: commonConfig, 42 | getTokenApprovalsForAddress: commonConfig, 43 | fetchRecentTransactions: fetchTransactionsConfig, 44 | getTransactionSummaryForAddress: commonConfig, 45 | getAllTransactionsInBlock: getAllTransactionsInBlockConfig, 46 | getBulkTimeBucketTransactionsForAddress: getBulkTimeBucketTransactionsConfig, 47 | }; 48 | 49 | async function main() { 50 | async function executeChainstackFunction(functionName, config) { 51 | console.time(`${functionName} execution time`); 52 | 53 | try { 54 | const data = await chainstack[functionName](config); 55 | console.log(`Done with ${functionName}`); 56 | // console.log(`${functionName} data:`, JSON.stringify(data, null, 2)); 57 | } catch (error) { 58 | console.error(`Failed to execute ${functionName}:`, error); 59 | } finally { 60 | console.timeEnd(`${functionName} execution time`); 61 | } 62 | } 63 | 64 | // Execute all functions sequentially 65 | for (const [functionName, config] of Object.entries(functionsConfigMap)) { 66 | await executeChainstackFunction(functionName, config); 67 | } 68 | } 69 | 70 | 71 | main() 72 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Serverless directories 108 | .serverless/ 109 | 110 | # FuseBox cache 111 | .fusebox/ 112 | 113 | # DynamoDB Local files 114 | .dynamodb/ 115 | 116 | # TernJS port file 117 | .tern-port 118 | 119 | # Stores VSCode versions used for testing VSCode extensions 120 | .vscode-test 121 | 122 | # yarn v2 123 | .yarn/cache 124 | .yarn/unplugged 125 | .yarn/build-state.yml 126 | .yarn/install-state.gz 127 | .pnp.* 128 | -------------------------------------------------------------------------------- /src/utils/balances.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | const { COVALENT_BASE_URL } = require('../config/config'); 3 | 4 | module.exports = function(ChainstackApi) { 5 | ChainstackApi.prototype.fetchTokenBalances = async function({ chainName, walletAddress, currency = "USD", nft = true, noNftFetch = false, noSpam = false }) { 6 | try { 7 | const validatedToken = await this.validateToken(); 8 | 9 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/address/${walletAddress}/balances_v2/`); 10 | const params = { 'quote-currency': currency, nft, 'no-nft-fetch': noNftFetch, 'no-spam': noSpam }; 11 | url.search = new URLSearchParams(params).toString(); 12 | 13 | const response = await axios.get(url, { 14 | headers: { 15 | 'Authorization': `Bearer ${validatedToken}` 16 | } 17 | }); 18 | 19 | return response.data; 20 | } catch (error) { 21 | console.error('Error fetching token balances for wallet:', walletAddress, 'on chain:', chainName, 'Error:', error); 22 | throw new Error(`Failed to fetch token balances for wallet ${walletAddress} on chain ${chainName}: ${error.message}`); 23 | } 24 | } 25 | 26 | ChainstackApi.prototype.fetchHistoricalPortfolioValue = async function({ chainName, walletAddress, currency = "USD", days }) { 27 | try { 28 | const validatedToken = await this.validateToken(); 29 | 30 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/address/${walletAddress}/portfolio_v2/`); 31 | const params = { 'quote-currency': currency, 'days': days }; 32 | url.search = new URLSearchParams(params).toString(); 33 | 34 | const response = await axios.get(url, { 35 | headers: { 36 | 'Authorization': `Bearer ${validatedToken}` 37 | } 38 | }); 39 | 40 | return response.data; 41 | } catch (error) { 42 | console.error('Error fetching historical portfolio value for wallet:', walletAddress, 'on chain:', chainName, 'Error:', error); 43 | throw new Error(`Failed to fetch historical portfolio value for wallet ${walletAddress} on chain ${chainName}: ${error.message}`); 44 | } 45 | } 46 | 47 | ChainstackApi.prototype.fetchERC20TokenTransfers = async function({ chainName, walletAddress, currency = "USD", contractAddress, startingBlock, endingBlock }) { 48 | try { 49 | const validatedToken = await this.validateToken(); 50 | 51 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/address/${walletAddress}/transfers_v2/`); 52 | const params = { 53 | 'quote-currency': currency, 54 | 'contract-address': contractAddress, 55 | 'starting-block': startingBlock, 56 | 'ending-block': endingBlock 57 | }; 58 | url.search = new URLSearchParams(params).toString(); 59 | 60 | const response = await axios.get(url, { 61 | headers: { 62 | 'Authorization': `Bearer ${validatedToken}` 63 | } 64 | }); 65 | 66 | return response.data; 67 | } catch (error) { 68 | console.error('Error fetching ERC20 token transfers for wallet:', walletAddress, 'on chain:', chainName, 'Error:', error); 69 | throw new Error(`Failed to fetch ERC20 token transfers for wallet ${walletAddress} on chain ${chainName}: ${error.message}`); 70 | } 71 | } 72 | 73 | ChainstackApi.prototype.fetchTokenHolders = async function({ chainName, tokenAddress, blockHeight, pageSize, pageNumber }) { 74 | try { 75 | const validatedToken = await this.validateToken(); 76 | 77 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/tokens/${tokenAddress}/token_holders_v2/`); 78 | const params = { 79 | 'block-height': blockHeight, 80 | 'page-size': pageSize, 81 | 'page-number': pageNumber 82 | }; 83 | url.search = new URLSearchParams(params).toString(); 84 | 85 | const response = await axios.get(url, { 86 | headers: { 87 | 'Authorization': `Bearer ${validatedToken}` 88 | } 89 | }); 90 | 91 | return response.data; 92 | } catch (error) { 93 | console.error('Error fetching token holders for token:', tokenAddress, 'on chain:', chainName, 'Error:', error); 94 | throw new Error(`Failed to fetch token holders for token ${tokenAddress} on chain ${chainName}: ${error.message}`); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/utils/base.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | const { COVALENT_BASE_URL } = require('../config/config'); 3 | 4 | module.exports = function(ChainstackApi) { 5 | ChainstackApi.prototype.fetchLogEvents = async function({ chainName, contractAddress, startingBlock, endingBlock }) { 6 | try { 7 | const validatedToken = await this.validateToken(); 8 | 9 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/events/address/${contractAddress}/`); 10 | const params = { 'starting-block': startingBlock, 'ending-block': endingBlock }; 11 | url.search = new URLSearchParams(params).toString(); 12 | 13 | const response = await axios.get(url, { 14 | headers: { 15 | 'Authorization': `Bearer ${validatedToken}` 16 | } 17 | }); 18 | 19 | return response.data; 20 | } catch (error) { 21 | console.error('Error fetching log events for contract:', contractAddress, 'on chain:', chainName, 'Error:', error); 22 | throw new Error(`Failed to fetch log events for contract ${contractAddress} on chain ${chainName}: ${error.message}`); 23 | } 24 | } 25 | 26 | ChainstackApi.prototype.fetchBlock = async function({ chainName, blockHeight }) { 27 | try { 28 | const validatedToken = await this.validateToken(); 29 | 30 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/block_v2/${blockHeight}/`); 31 | 32 | const response = await axios.get(url, { 33 | headers: { 34 | 'Authorization': `Bearer ${validatedToken}` 35 | } 36 | }); 37 | 38 | return response.data; 39 | } catch (error) { 40 | console.error('Error fetching block:', blockHeight, 'on chain:', chainName, 'Error:', error); 41 | throw new Error(`Failed to fetch block ${blockHeight} on chain ${chainName}: ${error.message}`); 42 | } 43 | } 44 | 45 | ChainstackApi.prototype.resolveAddress = async function({ chainName, walletAddress }) { 46 | try { 47 | const validatedToken = await this.validateToken(); 48 | 49 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/address/${walletAddress}/resolve_address/`); 50 | 51 | const response = await axios.get(url, { 52 | headers: { 53 | 'Authorization': `Bearer ${validatedToken}` 54 | } 55 | }); 56 | 57 | return response.data; 58 | } catch (error) { 59 | console.error('Error resolving address:', walletAddress, 'on chain:', chainName, 'Error:', error); 60 | throw new Error(`Failed to resolve address ${walletAddress} on chain ${chainName}: ${error.message}`); 61 | } 62 | } 63 | 64 | ChainstackApi.prototype.getBlockHeights = async function({ chainName, startDate, endDate }) { 65 | try { 66 | const validatedToken = await this.validateToken(); 67 | 68 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/block_v2/${startDate}/${endDate}/`); 69 | 70 | const response = await axios.get(url, { 71 | headers: { 72 | 'Authorization': `Bearer ${validatedToken}` 73 | } 74 | }); 75 | 76 | return response.data; 77 | } catch (error) { 78 | console.error('Error fetching block heights between', startDate, 'and', endDate, 'on chain:', chainName, 'Error:', error); 79 | throw new Error(`Failed to fetch block heights between ${startDate} and ${endDate} on chain ${chainName}: ${error.message}`); 80 | } 81 | } 82 | 83 | ChainstackApi.prototype.getLogs = async function({ chainName, startingBlock, endingBlock, address, topics, blockHash, skipDecode }) { 84 | try { 85 | const validatedToken = await this.validateToken(); 86 | 87 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/events/`); 88 | const params = { 89 | 'starting-block': startingBlock, 90 | 'ending-block': endingBlock, 91 | 'address': address, 92 | 'topics': topics, 93 | 'block-hash': blockHash, 94 | 'skip-decode': skipDecode 95 | }; 96 | url.search = new URLSearchParams(params).toString(); 97 | 98 | const response = await axios.get(url, { 99 | headers: { 100 | 'Authorization': `Bearer ${validatedToken}` 101 | } 102 | }); 103 | 104 | return response.data; 105 | } catch (error) { 106 | console.error('Error fetching logs on chain:', chainName, 'Error:', error); 107 | throw new Error(`Failed to fetch logs on chain ${chainName}: ${error.message}`); 108 | } 109 | } 110 | 111 | ChainstackApi.prototype.getLogsByTopicHash = async function({ chainName, topicHash, startingBlock, endingBlock, secondaryTopics }) { 112 | try { 113 | const validatedToken = await this.validateToken(); 114 | 115 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/events/topics/${topicHash}/`); 116 | const params = { 117 | 'starting-block': startingBlock, 118 | 'ending-block': endingBlock, 119 | 'secondary-topics': secondaryTopics 120 | }; 121 | url.search = new URLSearchParams(params).toString(); 122 | 123 | const response = await axios.get(url, { 124 | headers: { 125 | 'Authorization': `Bearer ${validatedToken}` 126 | } 127 | }); 128 | 129 | return response.data; 130 | } catch (error) { 131 | console.error('Error fetching log events by topic hash:', topicHash, 'on chain:', chainName, 'Error:', error); 132 | throw new Error(`Failed to fetch log events by topic hash ${topicHash} on chain ${chainName}: ${error.message}`); 133 | } 134 | } 135 | 136 | ChainstackApi.prototype.getAllChains = async function() { 137 | try { 138 | const validatedToken = await this.validateToken(); 139 | 140 | const url = new URL(`${COVALENT_BASE_URL}/chains/`); 141 | 142 | const response = await axios.get(url, { 143 | headers: { 144 | 'Authorization': `Bearer ${validatedToken}` 145 | } 146 | }); 147 | 148 | return response.data; 149 | } catch (error) { 150 | console.error('Error fetching all chains:', error); 151 | throw new Error(`Failed to fetch all chains: ${error.message}`); 152 | } 153 | } 154 | 155 | ChainstackApi.prototype.getAllChainStatuses = async function() { 156 | try { 157 | const validatedToken = await this.validateToken(); 158 | 159 | const url = new URL(`${COVALENT_BASE_URL}/chains/status/`); 160 | 161 | const response = await axios.get(url, { 162 | headers: { 163 | 'Authorization': `Bearer ${validatedToken}` 164 | } 165 | }); 166 | 167 | return response.data; 168 | } catch (error) { 169 | console.error('Error fetching all chain statuses:', error); 170 | throw new Error(`Failed to fetch all chain statuses: ${error.message}`); 171 | } 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Labs 2 | 3 |

4 |

Chainstack is the leading suite of services connecting developers with Web3 infrastructure

5 |

6 | 7 |

8 |   9 |   10 |   11 |   12 |   13 |

14 | 15 |

16 | • Homepage • 17 | Supported protocols • 18 | Chainstack blog • 19 | Chainstack docs • 20 | Blockchain API reference
21 | • Start for free • 22 |

23 | 24 | # Chainstack Covalent API JavaScript SDK 25 | 26 | A JavaScript SDK designed to streamline the process of developing using the integration of Chainstack with Covalent APIs, enhancing the ease of use and efficiency. 27 | 28 | ## Quickstart 29 | 30 | * Install the [Chainstack-Covalent integration](https://docs.chainstack.com/docs/work-with-chainstack-marketplace#install-an-app) from your Chainstack console. 31 | 32 | * Get a [Chainstack API key](https://docs.chainstack.com/reference/platform-api-getting-started#create-api-key). 33 | 34 | * In your project's directory, install the Chainstack SDK: 35 | 36 | ```sh 37 | npm i chainstack-covalent-sdk 38 | ``` 39 | 40 | * In a new file, import the Chainstack SDK and use your Chainstack API key in the constructor: 41 | 42 | ```js 43 | const {ChainstackApi} = require("chainstack-covalent-sdk") 44 | 45 | const CHAINSTACK_API_KEY = 'YOUR_CHAINSTACK_API_KEY' 46 | const chainstack = new ChainstackApi(CHAINSTACK_API_KEY); 47 | ``` 48 | 49 | * (Optional but recommended) — The Chainstack-Covalent SDK comes with the `dotenv` package included, so you can use a `.env` file to import the Chainstack API key: 50 | 51 | - Create a `.env` file with your Chainstack API key: 52 | 53 | ```env 54 | CHAINSTACK_API_KEY="YOUR_CHAINSTACK_API_KEY" 55 | ``` 56 | 57 | - Import it in your project: 58 | 59 | ```js 60 | const {ChainstackApi} = require("chainstack-covalent-sdk") 61 | 62 | const CHAINSTACK_API_KEY = process.env.CHAINSTACK_API_KEY 63 | const chainstack = new ChainstackApi(CHAINSTACK_API_KEY); 64 | ``` 65 | 66 | ## Usage 67 | 68 | The Chainstack-Covalent SDK has many endpoints to get all sorts of data, from smart contract deployments to NFT data. Each endpoint takes an object as a parameter to configure the call to the Covalent API. 69 | 70 | ### Fetch token balances 71 | 72 | This endpoint fetches all the token balances from the specified address on the selected chain: 73 | 74 | ```js 75 | const {ChainstackApi} = require("chainstack-covalent-sdk") 76 | 77 | const CHAINSTACK_API_KEY = process.env.CHAINSTACK_API_KEY 78 | const chainstack = new ChainstackApi(CHAINSTACK_API_KEY); 79 | 80 | // Config parameters 81 | const parameters = { 82 | chainName: 'eth-mainnet', 83 | walletAddress: '0xae2Fc483527B8EF99EB5D9B44875F005ba1FaE13', 84 | currency: 'USD', 85 | nft: true, 86 | noNftFetch: false, 87 | noSpam: true, 88 | }; 89 | 90 | 91 | chainstack.fetchTokenBalances(parameters) 92 | .then(data => console.log(data)) 93 | .catch(error => console.error(error)); 94 | ``` 95 | 96 | #### Explain the parameter object 97 | 98 | The parameters object allows for fine tuning of your request, here is the explanation about the configuration parameters for `fetchTokenBalances`: 99 | 100 | 1. **chainName** (string, required): This parameter represents the name of the blockchain network you're interested in. For example, 'eth-mainnet' for the Ethereum mainnet. Find a complete list on the [Covalent docs](https://www.covalenthq.com/docs/networks/). 101 | 102 | ```javascript 103 | const chainName = 'eth-mainnet'; 104 | ``` 105 | 106 | 2. **walletAddress** (string, required): This is the address of the wallet for which you want to fetch token balances. If you pass in an Ethereum Name Service (ENS) address or a RSK Name Service (RNS) address, it will be automatically resolved to the corresponding wallet address. 107 | 108 | ```javascript 109 | const walletAddress = '0xae2Fc483527B8EF99EB5D9B44875F005ba1FaE13'; 110 | ``` 111 | 112 | 3. **quote-currency** (string, optional): This is the currency in which you want the balances to be quoted, such as 'USD' for United States Dollars. If not provided, the balances may be returned in the native currency of the blockchain network. 113 | 114 | ```javascript 115 | const quoteCurrency = 'USD'; 116 | ``` 117 | 118 | 4. **nft** (boolean, optional): If set to `true`, Non-Fungible Tokens (NFTs) will be included in the response along with fungible tokens. If `false` or not provided, NFTs will not be included. 119 | 120 | ```javascript 121 | const nft = true; 122 | ``` 123 | 124 | 5. **no-nft-fetch** (boolean, optional): If set to `true`, the response will only include NFTs that have been cached. This can make the response faster, as it avoids having to fetch data about NFTs from the blockchain. If `false` or not provided, all NFTs will be included, regardless of whether they are cached. 125 | 126 | ```javascript 127 | const noNftFetch = false; 128 | ``` 129 | 130 | 6. **no-spam** (boolean, optional): If set to `true`, any tokens that are suspected to be spam will be excluded from the response. This currently supports 'eth-mainnet' and 'matic-mainnet'. If `false` or not provided, all tokens, including potential spam, will be included. 131 | 132 | ```javascript 133 | const noSpam = true; 134 | ``` 135 | 136 | Remember, this function returns a promise. Handle this promise appropriately in your code, either by using `.then()` and `.catch()` methods, or by using the `await` keyword inside an async function with a try-catch block. 137 | 138 | ## Work in progress 139 | 140 | This tool and its documentation is work in progress, we will be adding a complete list of endpoints available soon. 141 | -------------------------------------------------------------------------------- /src/utils/transactions.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | const { COVALENT_BASE_URL } = require('../config/config'); 3 | 4 | module.exports = function(ChainstackApi) { 5 | ChainstackApi.prototype.fetchRecentTransactions = async function({ chainName, walletAddress, currency="USD", noLogs=false }) { 6 | try { 7 | const validatedToken = await this.validateToken(); 8 | 9 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/address/${walletAddress}/transactions_v3/`); 10 | const params = { 'quote-currency': currency, 'no-logs': noLogs }; 11 | url.search = new URLSearchParams(params).toString(); 12 | 13 | const response = await axios.get(url, { 14 | headers: { 15 | 'Authorization': `Bearer ${validatedToken}` 16 | } 17 | }); 18 | 19 | return response.data; 20 | } catch (error) { 21 | console.error('Error fetching transactions for wallet:', walletAddress, 'on chain:', chainName, 'Error:', error); 22 | throw new Error(`Failed to fetch recent transactions for wallet ${walletAddress} on chain ${chainName}: ${error.message}`); 23 | } 24 | } 25 | 26 | ChainstackApi.prototype.getPaginatedTransactionsForAddress = async function({ chainName, walletAddress, page, quoteCurrency="USD", noLogs=false }) { 27 | try { 28 | const validatedToken = await this.validateToken(); 29 | 30 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/`); 31 | const params = { 32 | 'quote-currency': quoteCurrency, 33 | 'no-logs': noLogs 34 | }; 35 | url.search = new URLSearchParams(params).toString(); 36 | 37 | const response = await axios.get(url, { 38 | headers: { 39 | 'Authorization': `Bearer ${validatedToken}` 40 | } 41 | }); 42 | 43 | return response.data; 44 | } catch (error) { 45 | console.error('Error fetching paginated transactions for address:', walletAddress, 'on chain:', chainName, 'Error:', error); 46 | throw new Error(`Failed to fetch paginated transactions for address ${walletAddress} on chain ${chainName}: ${error.message}`); 47 | } 48 | } 49 | 50 | ChainstackApi.prototype.fetchContractDeploymentTransactions = async function({ chainName, walletAddress }) { 51 | try { 52 | const validatedToken = await this.validateToken(); 53 | 54 | let url = `${COVALENT_BASE_URL}/${chainName}/address/${walletAddress}/transactions_v3/page/0/`; 55 | 56 | let contractDeploymentTransactions = []; 57 | 58 | while (url) { 59 | const response = await axios.get(url, { 60 | headers: { 61 | 'Authorization': `Bearer ${validatedToken}` 62 | } 63 | }); 64 | 65 | const transactions = response.data.data.items; 66 | const filteredTransactions = transactions.filter(tx => tx.to_address === null); 67 | contractDeploymentTransactions = contractDeploymentTransactions.concat(filteredTransactions); 68 | 69 | url = response.data.data.links.next; 70 | } 71 | 72 | return contractDeploymentTransactions; 73 | 74 | } catch (error) { 75 | console.error('Error fetching contract deployment transactions for wallet:', walletAddress, 'on chain:', chainName, 'Error:', error); 76 | throw new Error(`Failed to fetch contract deployment transactions for wallet ${walletAddress} on chain ${chainName}: ${error.message}`); 77 | } 78 | } 79 | 80 | ChainstackApi.prototype.getTransaction = async function({ chainName, txHash, quoteCurrency="USD", noLogs=false, withDex=true, withNftSales=true, withLending=true }) { 81 | try { 82 | const validatedToken = await this.validateToken(); 83 | 84 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/transaction_v2/${txHash}/`); 85 | const params = { 86 | 'quote-currency': quoteCurrency, 87 | 'no-logs': noLogs, 88 | 'with-dex': withDex, 89 | 'with-nft-sales': withNftSales, 90 | 'with-lending': withLending 91 | }; 92 | url.search = new URLSearchParams(params).toString(); 93 | 94 | const response = await axios.get(url, { 95 | headers: { 96 | 'Authorization': `Bearer ${validatedToken}` 97 | } 98 | }); 99 | 100 | return response.data; 101 | } catch (error) { 102 | console.error('Error fetching transaction with hash:', txHash, 'on chain:', chainName, 'Error:', error); 103 | throw new Error(`Failed to fetch transaction with hash ${txHash} on chain ${chainName}: ${error.message}`); 104 | } 105 | } 106 | 107 | ChainstackApi.prototype.getTransactionSummaryForAddress = async function({ chainName, walletAddress }) { 108 | try { 109 | const validatedToken = await this.validateToken(); 110 | 111 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/address/${walletAddress}/transactions_summary/`); 112 | 113 | const response = await axios.get(url, { 114 | headers: { 115 | 'Authorization': `Bearer ${validatedToken}` 116 | } 117 | }); 118 | 119 | return response.data; 120 | } catch (error) { 121 | console.error('Error fetching transaction summary for address:', walletAddress, 'on chain:', chainName, 'Error:', error); 122 | throw new Error(`Failed to fetch transaction summary for address ${walletAddress} on chain ${chainName}: ${error.message}`); 123 | } 124 | } 125 | 126 | ChainstackApi.prototype.getAllTransactionsInBlock = async function({ chainName, blockHeight, quoteCurrency="USD", noLogs=false }) { 127 | try { 128 | const validatedToken = await this.validateToken(); 129 | 130 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/block/${blockHeight}/transactions_v3/`); 131 | const params = { 132 | 'quote-currency': quoteCurrency, 133 | 'no-logs': noLogs 134 | }; 135 | url.search = new URLSearchParams(params).toString(); 136 | 137 | const response = await axios.get(url, { 138 | headers: { 139 | 'Authorization': `Bearer ${validatedToken}` 140 | } 141 | }); 142 | 143 | return response.data; 144 | } catch (error) { 145 | console.error('Error fetching all transactions in block:', blockHeight, 'on chain:', chainName, 'Error:', error); 146 | throw new Error(`Failed to fetch all transactions in block ${blockHeight} on chain ${chainName}: ${error.message}`); 147 | } 148 | } 149 | 150 | ChainstackApi.prototype.getBulkTimeBucketTransactionsForAddress = async function({ chainName, walletAddress, timeBucket, quoteCurrency="USD", noLogs=false }) { 151 | try { 152 | const validatedToken = await this.validateToken(); 153 | 154 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/`); 155 | const params = { 156 | 'quote-currency': quoteCurrency, 157 | 'no-logs': noLogs 158 | }; 159 | url.search = new URLSearchParams(params).toString(); 160 | 161 | const response = await axios.get(url, { 162 | headers: { 163 | 'Authorization': `Bearer ${validatedToken}` 164 | } 165 | }); 166 | 167 | return response.data; 168 | } catch (error) { 169 | console.error('Error fetching bulk time bucket transactions for address:', walletAddress, 'on chain:', chainName, 'Error:', error); 170 | throw new Error(`Failed to fetch bulk time bucket transactions for address ${walletAddress} on chain ${chainName}: ${error.message}`); 171 | } 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /src/utils/nft.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | const { COVALENT_BASE_URL } = require('../config/config'); 3 | 4 | module.exports = function(ChainstackApi) { 5 | ChainstackApi.prototype.fetchNfts = async function({ chainName, walletAddress }) { 6 | try { 7 | const validatedToken = await this.validateToken(); 8 | 9 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/address/${walletAddress}/balances_nft/`); 10 | const params = { 'with-uncached': true }; 11 | url.search = new URLSearchParams(params).toString(); 12 | 13 | const response = await axios.get(url, { 14 | headers: { 15 | 'Authorization': `Bearer ${validatedToken}` 16 | } 17 | }); 18 | 19 | return response.data; 20 | } catch (error) { 21 | console.error('Error fetching NFTs for wallet:', walletAddress, 'on chain:', chainName, 'Error:', error); 22 | throw new Error(`Failed to fetch NFTs for wallet ${walletAddress} on chain ${chainName}: ${error.message}`); 23 | } 24 | } 25 | 26 | ChainstackApi.prototype.getNftsWithMetadata = async function({ chainName, contractAddress, noMetadata, pageSize, pageNumber, traitsFilter, valuesFilter }) { 27 | try { 28 | const validatedToken = await this.validateToken(); 29 | 30 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/nft/${contractAddress}/metadata/`); 31 | const params = { 'no-metadata': noMetadata, 'page-size': pageSize, 'page-number': pageNumber, 'traits-filter': traitsFilter, 'values-filter': valuesFilter }; 32 | url.search = new URLSearchParams(params).toString(); 33 | 34 | const response = await axios.get(url, { 35 | headers: { 36 | 'Authorization': `Bearer ${validatedToken}` 37 | } 38 | }); 39 | 40 | return response.data; 41 | } catch (error) { 42 | console.error('Error fetching NFTs with metadata for contract:', contractAddress, 'on chain:', chainName, 'Error:', error); 43 | throw new Error(`Failed to fetch NFTs with metadata for contract ${contractAddress} on chain ${chainName}: ${error.message}`); 44 | } 45 | } 46 | 47 | ChainstackApi.prototype.getSingleNftWithMetadata = async function({ chainName, contractAddress, tokenId, noMetadata }) { 48 | try { 49 | const validatedToken = await this.validateToken(); 50 | 51 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/nft/${contractAddress}/metadata/${tokenId}/`); 52 | const params = { 'no-metadata': noMetadata }; 53 | url.search = new URLSearchParams(params).toString(); 54 | 55 | const response = await axios.get(url, { 56 | headers: { 57 | 'Authorization': `Bearer ${validatedToken}` 58 | } 59 | }); 60 | 61 | return response.data; 62 | } catch (error) { 63 | console.error('Error fetching single NFT with metadata for token:', tokenId, 'on contract:', contractAddress, 'on chain:', chainName, 'Error:', error); 64 | throw new Error(`Failed to fetch single NFT with metadata for token ${tokenId} on contract ${contractAddress} on chain ${chainName}: ${error.message}`); 65 | } 66 | } 67 | 68 | ChainstackApi.prototype.getSingleNftWithExternalMetadata = async function({ chainName, contractAddress, tokenId }) { 69 | try { 70 | const validatedToken = await this.validateToken(); 71 | 72 | const url = `${COVALENT_BASE_URL}/${chainName}/tokens/${contractAddress}/nft_metadata/${tokenId}/`; 73 | 74 | const response = await axios.get(url, { 75 | headers: { 76 | 'Authorization': `Bearer ${validatedToken}` 77 | } 78 | }); 79 | 80 | return response.data; 81 | } catch (error) { 82 | console.error('Error fetching single NFT with external metadata for token:', tokenId, 'on contract:', contractAddress, 'on chain:', chainName, 'Error:', error); 83 | throw new Error(`Failed to fetch single NFT with external metadata for token ${tokenId} on contract ${contractAddress} on chain ${chainName}: ${error.message}`); 84 | } 85 | } 86 | 87 | ChainstackApi.prototype.getNftTransactionsForContract = async function({ chainName, contractAddress, tokenId, noSpam = false }) { 88 | try { 89 | const validatedToken = await this.validateToken(); 90 | 91 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/`); 92 | 93 | const params = { 'no-spam': noSpam }; 94 | url.search = new URLSearchParams(params).toString(); 95 | 96 | const response = await axios.get(url, { 97 | headers: { 98 | 'Authorization': `Bearer ${validatedToken}` 99 | } 100 | }); 101 | 102 | return response.data; 103 | } catch (error) { 104 | console.error('Error fetching NFT transactions for token:', tokenId, 'on contract:', contractAddress, 'on chain:', chainName, 'Error:', error); 105 | throw new Error(`Failed to fetch NFT transactions for token ${tokenId} on contract ${contractAddress} on chain ${chainName}: ${error.message}`); 106 | } 107 | } 108 | 109 | ChainstackApi.prototype.getTraitsForCollection = async function({ chainName, collectionContract }) { 110 | try { 111 | const validatedToken = await this.validateToken(); 112 | 113 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/nft/${collectionContract}/traits/`); 114 | 115 | const response = await axios.get(url, { 116 | headers: { 117 | 'Authorization': `Bearer ${validatedToken}` 118 | } 119 | }); 120 | 121 | return response.data; 122 | } catch (error) { 123 | console.error('Error fetching traits for collection:', collectionContract, 'on chain:', chainName, 'Error:', error); 124 | throw new Error(`Failed to fetch traits for collection ${collectionContract} on chain ${chainName}: ${error.message}`); 125 | } 126 | } 127 | 128 | ChainstackApi.prototype.getTraitSummaryForCollection = async function({ chainName, collectionContract }) { 129 | try { 130 | const validatedToken = await this.validateToken(); 131 | 132 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/nft/${collectionContract}/traits_summary/`); 133 | 134 | const response = await axios.get(url, { 135 | headers: { 136 | 'Authorization': `Bearer ${validatedToken}` 137 | } 138 | }); 139 | 140 | return response.data; 141 | } catch (error) { 142 | console.error('Error fetching trait summary for collection:', collectionContract, 'on chain:', chainName, 'Error:', error); 143 | throw new Error(`Failed to fetch trait summary for collection ${collectionContract} on chain ${chainName}: ${error.message}`); 144 | } 145 | } 146 | 147 | ChainstackApi.prototype.getAttributesForCollectionTrait = async function({ chainName, collectionContract, trait }) { 148 | try { 149 | const validatedToken = await this.validateToken(); 150 | 151 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/`); 152 | 153 | const response = await axios.get(url, { 154 | headers: { 155 | 'Authorization': `Bearer ${validatedToken}` 156 | } 157 | }); 158 | 159 | return response.data; 160 | } catch (error) { 161 | console.error('Error fetching attributes for collection trait:', trait, 'on chain:', chainName, 'Error:', error); 162 | throw new Error(`Failed to fetch attributes for collection trait ${trait} on chain ${chainName}: ${error.message}`); 163 | } 164 | } 165 | 166 | ChainstackApi.prototype.getChainCollections = async function({ chainName, pageSize, pageNumber, noSpam = false }) { 167 | try { 168 | const validatedToken = await this.validateToken(); 169 | 170 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/nft/collections/`); 171 | const params = { 172 | 'page-size': pageSize, 173 | 'page-number': pageNumber, 174 | 'no-spam': noSpam 175 | }; 176 | url.search = new URLSearchParams(params).toString(); 177 | 178 | const response = await axios.get(url, { 179 | headers: { 180 | 'Authorization': `Bearer ${validatedToken}` 181 | } 182 | }); 183 | 184 | return response.data; 185 | } catch (error) { 186 | console.error('Error fetching chain collections on chain:', chainName, 'Error:', error); 187 | throw new Error(`Failed to fetch chain collections on chain ${chainName}: ${error.message}`); 188 | } 189 | } 190 | 191 | ChainstackApi.prototype.checkOwnershipInNftCollection = async function({ chainName, walletAddress, collectionContract }) { 192 | try { 193 | const validatedToken = await this.validateToken(); 194 | 195 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/address/${walletAddress}/collection/${collectionContract}/`); 196 | 197 | const response = await axios.get(url, { 198 | headers: { 199 | 'Authorization': `Bearer ${validatedToken}` 200 | } 201 | }); 202 | 203 | return response.data; 204 | } catch (error) { 205 | console.error('Error checking ownership in NFT collection:', collectionContract, 'Error:', error); 206 | throw new Error(`Failed to check ownership in NFT collection ${collectionContract}: ${error.message}`); 207 | } 208 | } 209 | 210 | ChainstackApi.prototype.checkOwnershipInNftCollectionForSpecificToken = async function({ chainName, walletAddress, collectionContract, tokenId }) { 211 | try { 212 | const validatedToken = await this.validateToken(); 213 | 214 | const url = new URL(`${COVALENT_BASE_URL}/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/`); 215 | 216 | const response = await axios.get(url, { 217 | headers: { 218 | 'Authorization': `Bearer ${validatedToken}` 219 | } 220 | }); 221 | 222 | return response.data; 223 | } catch (error) { 224 | console.error('Error checking ownership in NFT collection for specific token:', tokenId, 'Error:', error); 225 | throw new Error(`Failed to check ownership in NFT collection for specific token ${tokenId}: ${error.message}`); 226 | } 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------