avalanche 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c2715ac0dee6e2104552ea61fa836ad5836749acbc5b4fde6bcc99c3e0c2d61d
4
+ data.tar.gz: 751c8ff597d3bb0b8e707e65bd88dfecfa753a3d8d3ec6972da06304fa6680f8
5
+ SHA512:
6
+ metadata.gz: 6e8baeae9864bc8594411e3d43fb9b486e86ee81219c091d1c3fd14122ee112b0f0a61df31b0f7ed2b3310b9cde43e4f26a431d95900872e2d446c8d25bd0ebb
7
+ data.tar.gz: d063ec6239bc5ecc875cb723a1a826a1ccc546001ceb0af7d7655d06f9ef559cb05748873a0270faf28bb68a5a4ca2238c87b5748715e76e5aa61bb41a54dfc9
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-08-31
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Andres Yebra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,153 @@
1
+ # Avalanche Ruby SDK
2
+
3
+ [Avalanche](https://www.avax.network/) is a decentralized, open-source Layer-1 blockchain platform developed.
4
+
5
+ This Ruby SDK provides a convenient way to interact with the Avalanche APIs.
6
+
7
+ [AvaCloud](https://www.avacloud.io/) is a powerful and flexible toolset designed to simplify the integration with AvaCloud's suite of blockchain services.
8
+
9
+
10
+ ## Documentation
11
+
12
+ For detailed API documentation, please visit: [Avalanche API Documentation](https://developers.avacloud.io/introduction)
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'avalanche'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```bash
25
+ $ bundle install
26
+ ```
27
+
28
+ Or install it yourself as:
29
+
30
+ ```bash
31
+ $ gem install avalanche
32
+ ```
33
+
34
+ ## Configuration
35
+
36
+ Add the following configuration to `config/initializers/avalanche.rb`:
37
+
38
+ ```ruby
39
+ Avalanche::AvaCloud.configure do |config|
40
+ config.api_key = "avacloud_api_key"
41
+ config.network = "testnet"
42
+ config.chain_id = 1
43
+ end
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ### Avalanche AvaCloud Data API
49
+
50
+ ```ruby
51
+ chains = Avalanche::AvaCloud::Data::EVM::Chains.chains
52
+ ```
53
+
54
+ ```json
55
+ {
56
+ "chains": [
57
+ {
58
+ "chainId": "<string>",
59
+ "status": "OK",
60
+ "chainName": "<string>",
61
+ "description": "<string>",
62
+ "platformChainId": "<string>",
63
+ "subnetId": "<string>",
64
+ "vmId": "<string>",
65
+ "vmName": "EVM",
66
+ "explorerUrl": "<string>",
67
+ "rpcUrl": "<string>",
68
+ "wsUrl": "<string>",
69
+ "isTestnet": true,
70
+ "utilityAddresses": {
71
+ "multicall": "<string>"
72
+ },
73
+ "networkToken": {
74
+ "name": "Wrapped AVAX",
75
+ "symbol": "WAVAX",
76
+ "decimals": 18,
77
+ "logoUri": "https://images.ctfassets.net/gcj8jwzm6086/5VHupNKwnDYJvqMENeV7iJ/fdd6326b7a82c8388e4ee9d4be7062d4/avalanche-avax-logo.svg",
78
+ "description": "<string>"
79
+ },
80
+ "chainLogoUri": "<string>",
81
+ "private": true,
82
+ "enabledFeatures": [
83
+ "nftIndexing"
84
+ ]
85
+ }
86
+ ]
87
+ }
88
+ ```
89
+
90
+ ### Avalanche AvaCloud Metrics API
91
+
92
+ ```ruby
93
+ metrics = Avalanche::AvaCloud::Metrics::Chains.chains
94
+ ```
95
+
96
+ ```json
97
+ {
98
+ "chains": [
99
+ {
100
+ "evmChainId": 43114,
101
+ "chainName": "c_chain",
102
+ "blockchainId": "2q9e4r6Mu3U68nU1fYjgbR6JvwrRx36CohpAX5UQxse55x1Q5",
103
+ "subnetId": "11111111111111111111111111111111LpoYY",
104
+ "network": "mainnet"
105
+ }
106
+ ]
107
+ }
108
+ ```
109
+
110
+ ### Avalanche AvaCloud Webhook API
111
+
112
+ ```ruby
113
+ webhooks = Avalanche::AvaCloud::Webhooks::Webhook.lists
114
+ ```
115
+
116
+ ```json
117
+ {
118
+ "webhooks": [
119
+ {
120
+ "id": "<string>",
121
+ "url": "<string>",
122
+ "chainId": "<string>",
123
+ "status": "active",
124
+ "createdAt": 123,
125
+ "name": "<string>",
126
+ "description": "<string>",
127
+ "eventType": "address_activity",
128
+ "metadata": {
129
+ "eventSignatures": [
130
+ "0x61cbb2a3dee0b6064c2e681aadd61677fb4ef319f0b547508d495626f5a62f64"
131
+ ],
132
+ "addresses": [
133
+ "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E"
134
+ ]
135
+ },
136
+ "includeInternalTxs": true,
137
+ "includeLogs": true
138
+ }
139
+ ]
140
+ }
141
+ ```
142
+
143
+ ## Contributing
144
+
145
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/avalanche. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/avalanche/blob/master/CODE_OF_CONDUCT.md).
146
+
147
+ ## License
148
+
149
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
150
+
151
+ ## Code of Conduct
152
+
153
+ Everyone interacting in the Avalanche project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/avalanche/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday/retry"
5
+
6
+ module Avalanche
7
+ module AvaCloud
8
+ # Base API class to connect with Data, Metrics and WebHook AvaCloud API.
9
+ class BaseApi
10
+ # Method to start a new Api connection.
11
+ # @param url_api [String]
12
+ # @param require_auth [Boolean]
13
+ # @return [Faraday::Connection]
14
+ def initialize(url_api:, require_auth: true)
15
+ @base_url_api = url_api
16
+ @require_auth = require_auth
17
+ @connection = Faraday.new(url: base_url_api) do |c|
18
+ c.request :json
19
+ c.response :json
20
+ c.use Faraday::Retry::Middleware
21
+ c.adapter Faraday.default_adapter
22
+ c.headers = headers
23
+ end
24
+ end
25
+
26
+ # Method to make GET request.
27
+ # @param path [String]
28
+ # @param params [Hash{Symbol->Object}]
29
+ # @return [Hash{Symbol->Object}]
30
+ def get(path, params = {})
31
+ handle_response do
32
+ @connection.get(path, params)
33
+ end
34
+ end
35
+
36
+ # Method to make POST request.
37
+ # @param path [String]
38
+ # @param body [Hash{Symbol->Object}]
39
+ # @return [Hash{Symbol->Object}]
40
+ def post(path, body = {})
41
+ handle_response do
42
+ @connection.post(path, body)
43
+ end
44
+ end
45
+
46
+ # Method to make PUT request.
47
+ # @param path [String]
48
+ # @param body [Hash{Symbol->Object}]
49
+ # @return [Hash{Symbol->Object}]
50
+ def put(path, body = {})
51
+ handle_response do
52
+ @connection.put(path, body)
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ attr_reader :base_url_api, :require_auth
59
+
60
+ # Method to set Http headers.
61
+ # @return [Hash{Symbol->Object}]
62
+ def headers
63
+ {
64
+ "x-glacier-api-key" => require_auth ? Avalanche::AvaCloud.config.api_key : nil,
65
+ "Content-Type" => "application/json"
66
+ }
67
+ end
68
+
69
+ # Method to handle API response(body, status, code).
70
+ # @return [Hash{Symbol->Object}]
71
+ def handle_response # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
72
+ response = yield
73
+ case response.status
74
+ when 200..299
75
+ response.body
76
+ when 400
77
+ raise Avalanche::AvaCloud::BadRequestError.new(response.status, response.body)
78
+ when 401
79
+ raise Avalanche::AvaCloud::UnauthorizedError.new(response.status, response.body)
80
+ when 404
81
+ raise Avalanche::AvaCloud::NotFoundError.new(response.status, response.body)
82
+ when 500..599
83
+ raise Avalanche::AvaCloud::ServerError.new(response.status, response.body)
84
+ else
85
+ raise Avalanche::AvaCloud::APIError.new(response.status, response.body)
86
+ end
87
+ rescue Faraday::Error => e
88
+ raise Avalanche::AvaCloud::Error, "Network error: #{e.message}"
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avalanche
4
+ module AvaCloud
5
+ module Data
6
+ module EVM
7
+ # Avalanche Data API provides endpoints for the latest information on avalanche balances.
8
+ # @see https://developers.avacloud.io/data-api/evm-balances
9
+ class Balances
10
+ class << self
11
+ # Lists ERC-20 token balances of a wallet address.
12
+ # Balance at a given block can be retrieved with the blockNumber parameter.
13
+ # Balance for specific contracts can be retrieved with the contractAddresses parameter.
14
+ # @see https://developers.avacloud.io/data-api/evm-balances/list-erc-20-balances
15
+ # @param address [String]
16
+ # @return [Array<Hash{Symbol->Object}>]
17
+ def erc20_balances(address = nil)
18
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/addresses/#{address}/balances:listErc20")
19
+ end
20
+
21
+ # Lists ERC-721 token balances of a wallet address.
22
+ # Balance at a given block can be retrieved with the blockNumber parameter.
23
+ # Balance for specific contracts can be retrieved with the contractAddresses parameter.
24
+ # @see https://developers.avacloud.io/data-api/evm-balances/list-erc-721-balances
25
+ # @param address [String]
26
+ # @return [Array<Hash{Symbol->Object}>]
27
+ def erc721_balances(address = nil)
28
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/addresses/#{address}/balances:listErc721")
29
+ end
30
+
31
+ # Lists ERC-1155 token balances of a wallet address.
32
+ # Balance at a given block can be retrieved with the blockNumber parameter.
33
+ # Balance for specific contracts can be retrieved with the contractAddresses parameter.
34
+ # @see https://developers.avacloud.io/data-api/evm-balances/list-erc-1155-balances
35
+ # @param address [String]
36
+ # @return [Array<Hash{Symbol->Object}>]
37
+ def erc1155_balances(address = nil)
38
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/addresses/#{address}/balances:listErc1155")
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avalanche
4
+ module AvaCloud
5
+ module Data
6
+ module EVM
7
+ # Avalanche Data API provides endpoints for the latest information on avalanche blocks.
8
+ # @see https://developers.avacloud.io/data-api/evm-blocks
9
+ class Blocks
10
+ class << self
11
+ # Lists the latest indexed blocks on the EVM-compatible chain sorted in descending order by block timestamp.
12
+ # @see https://developers.avacloud.io/data-api/evm-blocks/list-latest-blocks
13
+ # @return [Array<Hash{Symbol->Object}>]
14
+ def blocks
15
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/blocks")
16
+ end
17
+
18
+ # Gets the details of an individual block on the EVM-compatible chain.
19
+ # @see https://developers.avacloud.io/data-api/evm-blocks/get-block
20
+ # @param block_id [String]
21
+ # @return [Hash{Symbol->Object}]
22
+ def block(block_id = nil)
23
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/blocks/#{block_id}")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avalanche
4
+ module AvaCloud
5
+ module Data
6
+ module EVM
7
+ # Avalanche Data API provides endpoints for the latest information on avalanche chains.
8
+ # @see https://developers.avacloud.io/data-api/evm-chains
9
+ class Chains
10
+ class << self
11
+ # Lists the AvaCloud supported EVM-compatible chains. Filterable by network.
12
+ # @see https://developers.avacloud.io/data-api/evm-chains/list-chains
13
+ # @return [Array<Hash{Symbol->Object}>]
14
+ def chains
15
+ DataApi.instance.get("/v1/chains")
16
+ end
17
+
18
+ # Gets chain information for the EVM-compatible chain if supported by AvaCloud.
19
+ # @see https://developers.avacloud.io/data-api/evm-chains/get-chain-information
20
+ # @param chain_id [String]
21
+ # @return [Hash{Symbol->Object}]
22
+ def chain(chain_id = nil)
23
+ DataApi.instance.get("/v1/chains/#{chain_id || Avalanche::AvaCloud.config.chain_id}")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avalanche
4
+ module AvaCloud
5
+ module Data
6
+ module EVM
7
+ # Avalanche Data API provides endpoints for the latest information on avalanche contracts.
8
+ # @see https://developers.avacloud.io/data-api/evm-contracts
9
+ class Contracts
10
+ class << self
11
+ # Gets metadata about the contract at the given address.
12
+ # @see https://developers.avacloud.io/data-api/evm-contracts/get-contract-metadata
13
+ # @return [Array<Hash{Symbol->Object}>]
14
+ def contract_metadata(address = nil)
15
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/addresses/#{address}")
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avalanche
4
+ module AvaCloud
5
+ module Data
6
+ module EVM
7
+ # Avalanche Data API provides endpoints for the latest information on avalanche NFTs.
8
+ # @see https://developers.avacloud.io/data-api/nfts
9
+ class Nfts
10
+ class << self
11
+ # Triggers reindexing of token metadata for an NFT token.
12
+ # Reindexing can only be called once per hour for each NFT token.
13
+ # @see https://developers.avacloud.io/data-api/nfts/reindex-nft-metadata
14
+ # @param address [String]
15
+ # @param token_id [String]
16
+ # @return [Array<Hash{Symbol->Object}>]
17
+ def reindexing_token(address = nil, token_id = nil)
18
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/nfts/collections/#{address}/tokens/#{token_id}:reindex")
19
+ end
20
+
21
+ # Lists tokens for an NFT contract.
22
+ # @see https://developers.avacloud.io/data-api/nfts/list-tokens
23
+ # @param address [String]
24
+ # @return [Array<Hash{Symbol->Object}>]
25
+ def tokens(address = nil)
26
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/nfts/collections/#{address}/tokens")
27
+ end
28
+
29
+ # Gets token details for a specific token of an NFT contract.
30
+ # @see https://developers.avacloud.io/data-api/nfts/get-token-details
31
+ # @param address [String]
32
+ # @param token_id [String]
33
+ # @return [Array<Hash{Symbol->Object}>]
34
+ def token(address = nil, token_id = nil)
35
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/nfts/collections/#{address}/tokens/#{token_id}")
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avalanche
4
+ module AvaCloud
5
+ module Data
6
+ module EVM
7
+ # Avalanche Data API provides endpoints for the latest information on avalanche transactions.
8
+ # @see https://developers.avacloud.io/data-api/evm-transactions
9
+ class Transactions
10
+ class << self
11
+ # If the address is a smart contract, returns the transaction in which it was deployed.
12
+ # @see https://developers.avacloud.io/data-api/evm-transactions/get-deployment-transaction
13
+ # @return [Array<Hash{Symbol->Object}>]
14
+ def deployment_transactions(address = nil)
15
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/contracts/#{address}/transactions:getDeployment")
16
+ end
17
+
18
+ # Lists all contracts deployed by the given address.
19
+ # @see https://developers.avacloud.io/data-api/evm-transactions/list-deployed-contracts
20
+ # @param address [String]
21
+ # @return [Hash{Symbol->Object}]
22
+ def contract_deployment_transactions(address = nil)
23
+ DataApi.instance.get("v1/chains/#{Avalanche::AvaCloud.config.chain_id}/contracts/#{address}/deployments")
24
+ end
25
+
26
+ # Returns a list of transactions where the given wallet address had an on-chain interaction
27
+ # for the given chain. The ERC-20 transfers, ERC-721 transfers, ERC-1155, and internal transactions returned
28
+ # are only those where the input address had an interaction. Specifically, those lists only include entries
29
+ # where the input address was the sender (from field) or the receiver (to field) for the sub-transaction.
30
+ # Therefore the transactions returned from this list may not be complete representations of the on-chain
31
+ # data. For a complete view of a transaction use the
32
+ # @see https://developers.avacloud.io/data-api/evm-transactions/list-transactions
33
+ # @param address [String]
34
+ # @return [Hash{Symbol->Object}]
35
+ def transactions(address = nil)
36
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/addresses/#{address}/transactions")
37
+ end
38
+
39
+ # Lists native transactions for an address.
40
+ # @see https://developers.avacloud.io/data-api/evm-transactions/list-native-transactions
41
+ # @param address [String]
42
+ # @return [Hash{Symbol->Object}]
43
+ def native_transactions(address = nil)
44
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/addresses/#{address}/transactions:listNative")
45
+ end
46
+
47
+ # Lists ERC-20 transfers for an address.
48
+ # @see https://developers.avacloud.io/data-api/evm-transactions/list-erc-20-transfers
49
+ # @param address [String]
50
+ # @return [Hash{Symbol->Object}]
51
+ def erc20_transactions(address = nil)
52
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/addresses/#{address}transactions:listErc20")
53
+ end
54
+
55
+ # Lists ERC-721 transfers for an address.
56
+ # @see https://developers.avacloud.io/data-api/evm-transactions/list-erc-721-transfers
57
+ # @param address [String]
58
+ # @return [Hash{Symbol->Object}]
59
+ def erc721_transactions(address = nil)
60
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/addresses/#{address}transactions:listErc721")
61
+ end
62
+
63
+ # Lists ERC-1155 transfers for an address.
64
+ # @see https://developers.avacloud.io/data-api/evm-transactions/list-erc-1155-transfers
65
+ # @param address [String]
66
+ # @return [Hash{Symbol->Object}]
67
+ def erc1155_transactions(address = nil)
68
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/addresses/#{address}transactions:listErc1155")
69
+ end
70
+
71
+ # Returns a list of internal transactions for an address and chain. Filterable by block range.
72
+ # Note that the internal transactions list only contains CALL or CALLCODE transactions with a non-zero value
73
+ # and CREATE/CREATE2/CREATE3 transactions. To get a complete list of internal transactions use the
74
+ # debug_ prefixed RPC methods on an archive node.
75
+ # @see https://developers.avacloud.io/data-api/evm-transactions/list-internal-transactions
76
+ # @param address [String]
77
+ # @return [Hash{Symbol->Object}]
78
+ def internal_transactions(address = nil)
79
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/addresses/#{address}transactions:listInternals")
80
+ end
81
+
82
+ # Gets the details of a single transaction.
83
+ # @see https://developers.avacloud.io/data-api/evm-transactions/get-transaction
84
+ # @param tx_hash [String]
85
+ # @return [Hash{Symbol->Object}]
86
+ def transaction(tx_hash = nil)
87
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/transactions/#{tx_hash}")
88
+ end
89
+
90
+ # Lists the transactions that occurred in a given block.
91
+ # @see https://developers.avacloud.io/data-api/evm-transactions/list-transactions-for-a-block
92
+ # @param block_id [String]
93
+ # @return [Hash{Symbol->Object}]
94
+ def block_transaction(block_id = nil)
95
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/blocks/#{block_id}/transactions")
96
+ end
97
+
98
+ # Lists the latest transactions.
99
+ # @see https://developers.avacloud.io/data-api/evm-transactions/list-latest-transactions
100
+ # @return [Hash{Symbol->Object}]
101
+ def latest_transactions
102
+ DataApi.instance.get("/v1/chains/#{Avalanche::AvaCloud.config.chain_id}/transactions")
103
+ end
104
+
105
+ # Lists the most recent transactions from all supported EVM-compatible chains.
106
+ # The results can be filtered based on transaction status.
107
+ # @see https://developers.avacloud.io/data-api/evm-transactions/list-the-latest-transactions-across-all-supported-evm-chains
108
+ # @return [Hash{Symbol->Object}]
109
+ def evms_latest_transactions
110
+ DataApi.instance.get("/v1/transactions")
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avalanche
4
+ module AvaCloud
5
+ # https://developers.avacloud.io/data-api/overview
6
+ class DataApi < AvaCloud::BaseApi
7
+ BASE_URL_API = "https://glacier-api.avax.network"
8
+
9
+ class << self
10
+ # @return [Api]
11
+ def instance
12
+ @instance ||= new
13
+ end
14
+ end
15
+
16
+ # Method to start a new Data API connection.
17
+ # @return [Faraday::Connection]
18
+ def initialize
19
+ super(url_api: BASE_URL_API, require_auth: true)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avalanche
4
+ module AvaCloud
5
+ # Standard error class.
6
+ class Error < StandardError; end
7
+
8
+ # Configuration error class.
9
+ class ConfigurationError < Error; end
10
+
11
+ # Missing Configuration error class.
12
+ class MissingConfigurationError < ConfigurationError; end
13
+
14
+ # API errors.
15
+ class APIError < Error
16
+ attr_reader :status, :body
17
+
18
+ # @param status [Integer]
19
+ # @param body [Hash{Symbol-Object}]
20
+ # @return [self]
21
+ def initialize(status, body)
22
+ @status = status
23
+ @body = body
24
+ super("API Error: #{status} - #{body}")
25
+ end
26
+ end
27
+
28
+ # Authentication errors.
29
+ class AuthenticationError < APIError; end
30
+
31
+ # Not found errors.
32
+ class NotFoundError < APIError; end
33
+
34
+ # Server errors.
35
+ class ServerError < APIError; end
36
+
37
+ # Bad Request errors.
38
+ class BadRequestError < APIError; end
39
+
40
+ # Unauthorized errors.
41
+ class UnauthorizedError < APIError; end
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avalanche
4
+ module AvaCloud
5
+ class Metrics
6
+ # Avalanche Data API provides endpoints for the latest information on avalanche chains.
7
+ # @see https://developers.avacloud.io/data-api/evm-chains
8
+ class Chains
9
+ class << self
10
+ # Get a list of Metrics API supported blockchains.
11
+ # @see https://developers.avacloud.io/metrics-api/evm-chains/get-a-list-of-supported-blockchains
12
+ # @return [Array<Hash{Symbol->Object}>]
13
+ def chains
14
+ MetricsApi.instance.get("/v2/chains")
15
+ end
16
+
17
+ # Get chain information for Metrics API supported blockchain.
18
+ # @see https://developers.avacloud.io/metrics-api/evm-chains/get-chain-information-for-supported-blockchain
19
+ # @param chain_id [String]
20
+ # @return [Hash{Symbol->Object}]
21
+ def chain(chain_id = nil)
22
+ MetricsApi.instance.get("/v2/chains/#{chain_id || Avalanche::AvaCloud.config.chain_id}")
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avalanche
4
+ module AvaCloud
5
+ # https://developers.avacloud.io/metrics-api/overview
6
+ class MetricsApi < AvaCloud::BaseApi
7
+ BASE_URL_API = "https://metrics.avax.network"
8
+
9
+ class << self
10
+ # @return [Api]
11
+ def instance
12
+ @instance ||= new
13
+ end
14
+ end
15
+
16
+ # Method to start a new Metric API connection.
17
+ # @return [Faraday::Connection]
18
+ def initialize
19
+ super(url_api: BASE_URL_API, require_auth: false)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avalanche
4
+ module AvaCloud
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avalanche
4
+ module AvaCloud
5
+ # https://developers.avacloud.io/webhooks-api/overview
6
+ class WebhookApi < AvaCloud::BaseApi
7
+ BASE_URL_API = "https://glacier-api.avax.network"
8
+
9
+ class << self
10
+ # @return [Api]
11
+ def instance
12
+ @instance ||= new
13
+ end
14
+ end
15
+
16
+ # Method to start a new Webhook API connection.
17
+ # @return [Faraday::Connection]
18
+ def initialize
19
+ super(url_api: BASE_URL_API, require_auth: true)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avalanche
4
+ module AvaCloud
5
+ class Webhooks
6
+ # Avalanche Data API provides endpoints for the latest information on avalanche webhook.
7
+ # @see https://developers.avacloud.io/webhooks-api/webhooks
8
+ class Webhook
9
+ class << self
10
+ # Lists webhooks for the user.
11
+ # @see https://developers.avacloud.io/webhooks-api/webhooks/list-webhooks
12
+ # @return [Array<Hash{Symbol->Object}>]
13
+ def lists
14
+ WebhookApi.instance.get("/v1/webhooks")
15
+ end
16
+
17
+ # Lists webhooks for the user.
18
+ # @see https://developers.avacloud.io/webhooks-api/webhooks/create-a-webhook
19
+ # @return [Array<Hash{Symbol->Object}>]
20
+ def create(params)
21
+ WebhookApi.instance.post("/v1/webhooks", params)
22
+ end
23
+
24
+ # Retrieves a webhook by ID.
25
+ # @see https://developers.avacloud.io/webhooks-api/webhooks/get-a-webhook-by-id
26
+ # @return [Array<Hash{Symbol->Object}>]
27
+ def retrieve(id = nil)
28
+ WebhookApi.instance.post("/v1/webhooks/#{id}")
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry-configurable"
4
+
5
+ # Base ava cloud lib class
6
+ require_relative "ava_cloud/version"
7
+ require_relative "ava_cloud/errors"
8
+ require_relative "ava_cloud/base_api"
9
+
10
+ # AvaCloud Data API
11
+ require_relative "ava_cloud/data_api"
12
+ require_relative "ava_cloud/data/evm/balances"
13
+ require_relative "ava_cloud/data/evm/blocks"
14
+ require_relative "ava_cloud/data/evm/chains"
15
+ require_relative "ava_cloud/data/evm/contracts"
16
+ require_relative "ava_cloud/data/evm/nfts"
17
+ require_relative "ava_cloud/data/evm/transactions"
18
+
19
+ # AvaCloud Metrics API
20
+ require_relative "ava_cloud/metrics_api"
21
+ require_relative "ava_cloud/metrics/chains"
22
+
23
+ # AvaCloud Webhook API
24
+ require_relative "ava_cloud/webhook_api"
25
+ require_relative "ava_cloud/webhooks/webhooks"
26
+
27
+ module Avalanche
28
+ # @example Configure AvaCloud
29
+ # Avalanche::AvaCloud.configure do |config|
30
+ # config.api_key = "your_api_key"
31
+ # config.network = "mainet"
32
+ # config.chain_id = "5207418"
33
+ # end
34
+ module AvaCloud
35
+ extend Dry::Configurable
36
+
37
+ setting :api_key, default: nil
38
+ setting :network, default: nil
39
+ setting :chain_id, default: nil
40
+ end
41
+ end
data/lib/avalanche.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "avalanche/ava_cloud"
4
+
5
+ # Avalanche gem
6
+ module Avalanche
7
+ end
data/sig/avalanche.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Avalanche
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: avalanche
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andres Yebra
8
+ autorequire: avalanche
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-configurable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday-retry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A Ruby SDK to interact with Avalanche's primary network, Avalanche L1s,
70
+ and Ethereum.
71
+ email:
72
+ - andres@even.biz
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - CHANGELOG.md
80
+ - CODE_OF_CONDUCT.md
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - lib/avalanche.rb
85
+ - lib/avalanche/ava_cloud.rb
86
+ - lib/avalanche/ava_cloud/base_api.rb
87
+ - lib/avalanche/ava_cloud/data/evm/balances.rb
88
+ - lib/avalanche/ava_cloud/data/evm/blocks.rb
89
+ - lib/avalanche/ava_cloud/data/evm/chains.rb
90
+ - lib/avalanche/ava_cloud/data/evm/contracts.rb
91
+ - lib/avalanche/ava_cloud/data/evm/nfts.rb
92
+ - lib/avalanche/ava_cloud/data/evm/transactions.rb
93
+ - lib/avalanche/ava_cloud/data_api.rb
94
+ - lib/avalanche/ava_cloud/errors.rb
95
+ - lib/avalanche/ava_cloud/metrics/chains.rb
96
+ - lib/avalanche/ava_cloud/metrics_api.rb
97
+ - lib/avalanche/ava_cloud/version.rb
98
+ - lib/avalanche/ava_cloud/webhook_api.rb
99
+ - lib/avalanche/ava_cloud/webhooks/webhooks.rb
100
+ - sig/avalanche.rbs
101
+ homepage: https://github.com/even-labs/avalanche
102
+ licenses:
103
+ - MIT
104
+ metadata:
105
+ allowed_push_host: https://rubygems.org
106
+ homepage_uri: https://github.com/even-labs/avalanche
107
+ source_code_uri: https://github.com/even-labs/avalanche
108
+ changelog_uri: https://github.com/even-labs/avalanche/blob/main/CHANGELOG.md
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 3.1.0
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 3.6.7
124
+ specification_version: 4
125
+ summary: Ruby SDK for Avalanche
126
+ test_files: []