Class: BlockGiven::Connectors::Alchemy
- Defined in:
- lib/block_given/connectors/alchemy.rb
Overview
Alchemy JSON-RPC connector. The endpoint is derived from the chain, so one connector instance can serve any Alchemy-supported network.
BlockGiven::Connectors::Alchemy.new(api_key: ENV["ALCHEMY_API_KEY"])
Constant Summary
Constants inherited from Http
Http::RETRIABLE_EXCEPTIONS, Http::RETRIABLE_RPC_CODES, Http::RETRIABLE_STATUSES
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Attributes inherited from Http
#headers, #retries, #retry_delay, #timeout, #url
Instance Method Summary collapse
- #endpoint(chain) ⇒ Object
-
#initialize(api_key:, timeout: 30, retries: 3, retry_delay: 0.5, logger: nil, headers: {}) ⇒ Alchemy
constructor
A new instance of Alchemy.
- #inspect ⇒ Object
-
#redact(endpoint) ⇒ Object
Keeps the network host visible, masks the key: https://base-mainnet.g.alchemy.com/v2/abcd….
Methods inherited from Http
Methods inherited from Base
Constructor Details
#initialize(api_key:, timeout: 30, retries: 3, retry_delay: 0.5, logger: nil, headers: {}) ⇒ Alchemy
Returns a new instance of Alchemy.
12 13 14 15 16 17 |
# File 'lib/block_given/connectors/alchemy.rb', line 12 def initialize(api_key:, timeout: 30, retries: 3, retry_delay: 0.5, logger: nil, headers: {}) raise ConfigurationError, "Alchemy api_key is required" if api_key.nil? || api_key.to_s.empty? @api_key = api_key.to_s super(url: nil, headers: headers, timeout: timeout, retries: retries, retry_delay: retry_delay, logger: logger) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
10 11 12 |
# File 'lib/block_given/connectors/alchemy.rb', line 10 def api_key @api_key end |
Instance Method Details
#endpoint(chain) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/block_given/connectors/alchemy.rb', line 19 def endpoint(chain) raise ConfigurationError, "Alchemy connector needs a chain" if chain.nil? raise ConfigurationError, "#{chain.name} is not available on Alchemy" unless chain.alchemy_network "https://#{chain.alchemy_network}.g.alchemy.com/v2/#{api_key}" end |
#inspect ⇒ Object
26 |
# File 'lib/block_given/connectors/alchemy.rb', line 26 def inspect = "#<BlockGiven::Connectors::Alchemy api_key=#{redacted_key}>" |
#redact(endpoint) ⇒ Object
Keeps the network host visible, masks the key: https://base-mainnet.g.alchemy.com/v2/abcd…
29 |
# File 'lib/block_given/connectors/alchemy.rb', line 29 def redact(endpoint) = endpoint.to_s.sub(api_key, redacted_key) |