Module: Coinbase
- Defined in:
- lib/coinbase.rb,
lib/coinbase/user.rb,
lib/coinbase/asset.rb,
lib/coinbase/trade.rb,
lib/coinbase/errors.rb,
lib/coinbase/wallet.rb,
lib/coinbase/address.rb,
lib/coinbase/balance.rb,
lib/coinbase/network.rb,
lib/coinbase/transfer.rb,
lib/coinbase/constants.rb,
lib/coinbase/middleware.rb,
lib/coinbase/balance_map.rb,
lib/coinbase/transaction.rb,
lib/coinbase/authenticator.rb,
lib/coinbase/server_signer.rb,
lib/coinbase/faucet_transaction.rb
Overview
The Coinbase SDK.
Defined Under Namespace
Modules: Client, Middleware Classes: APIError, Address, AlreadyExistsError, Asset, Authenticator, Balance, BalanceMap, Configuration, FaucetLimitReachedError, FaucetTransaction, InternalError, InvalidAddressError, InvalidAddressIDError, InvalidAmountError, InvalidAssetIDError, InvalidConfiguration, InvalidDestinationError, InvalidLimitError, InvalidNetworkIDError, InvalidPageError, InvalidSignedPayloadError, InvalidTransferIDError, InvalidTransferStatusError, InvalidWalletError, InvalidWalletIDError, MalformedRequestError, Network, NetworkFeatureUnsupportedError, NotFoundError, ResourceExhaustedError, ServerSigner, Trade, Transaction, Transfer, UnauthorizedError, UnimplementedError, UnsupportedAssetError, User, Wallet
Constant Summary collapse
- ERROR_CODE_TO_ERROR_CLASS =
{ 'unimplemented' => UnimplementedError, 'unauthorized' => , 'internal' => InternalError, 'not_found' => NotFoundError, 'invalid_wallet_id' => InvalidWalletIDError, 'invalid_address_id' => InvalidAddressIDError, 'invalid_wallet' => InvalidWalletError, 'invalid_address' => InvalidAddressError, 'invalid_amount' => InvalidAmountError, 'invalid_transfer_id' => InvalidTransferIDError, 'invalid_page_token' => InvalidPageError, 'invalid_page_limit' => InvalidLimitError, 'already_exists' => AlreadyExistsError, 'malformed_request' => MalformedRequestError, 'unsupported_asset' => UnsupportedAssetError, 'invalid_asset_id' => InvalidAssetIDError, 'invalid_destination' => InvalidDestinationError, 'invalid_network_id' => InvalidNetworkIDError, 'resource_exhausted' => ResourceExhaustedError, 'faucet_limit_reached' => FaucetLimitReachedError, 'invalid_signed_payload' => InvalidSignedPayloadError, 'invalid_transfer_status' => InvalidTransferStatusError, 'network_feature_unsupported' => NetworkFeatureUnsupportedError }.freeze
- BASE_SEPOLIA =
The Base Sepolia Network.
Network.new( network_id: :base_sepolia, display_name: 'Base Sepolia', protocol_family: :evm, is_testnet: true, native_asset_id: :eth, chain_id: 84_532 )
- GWEI_DECIMALS =
The number of decimal places in Gwei.
9
Class Method Summary collapse
-
.call_api ⇒ Object
Wraps a call to the Platform API to ensure that the error is caught and wrapped as an APIError.
-
.configuration ⇒ Configuration
Returns the configuration object.
-
.configure {|configuration| ... } ⇒ String
Configures the Coinbase SDK.
-
.configure_from_json(file_path = 'cdp_api_key.json') ⇒ String
Configures the Coinbase SDK from the given CDP API Key JSON file.
-
.default_user ⇒ Coinbase::User
Returns the default user.
-
.load_default_user ⇒ Coinbase::User
Loads the default user.
-
.normalize_network(network_sym) ⇒ String
Converts a network symbol to a string, replacing underscores with hyphens.
-
.to_sym(value) ⇒ Symbol
Converts a string to a symbol, replacing hyphens with underscores.
-
.use_server_signer? ⇒ bool
Returns whether to use a server signer to manage private keys.
Class Method Details
.call_api ⇒ Object
Wraps a call to the Platform API to ensure that the error is caught and wrapped as an APIError.
119 120 121 122 123 124 125 |
# File 'lib/coinbase.rb', line 119 def self.call_api yield rescue Coinbase::Client::ApiError => e raise Coinbase::APIError.from_error(e), cause: nil rescue StandardError => e raise e end |
.configuration ⇒ Configuration
Returns the configuration object.
28 29 30 |
# File 'lib/coinbase.rb', line 28 def self.configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ String
Configures the Coinbase SDK.
34 35 36 37 38 39 40 41 |
# File 'lib/coinbase.rb', line 34 def self.configure yield(configuration) raise InvalidConfiguration, 'API key private key is not set' unless configuration.api_key_private_key raise InvalidConfiguration, 'API key name is not set' unless configuration.api_key_name 'Successfully configured Coinbase SDK' end |
.configure_from_json(file_path = 'cdp_api_key.json') ⇒ String
Configures the Coinbase SDK from the given CDP API Key JSON file. file in the root directory by default.
47 48 49 50 51 52 53 54 |
# File 'lib/coinbase.rb', line 47 def self.configure_from_json(file_path = 'cdp_api_key.json') configuration.from_json(file_path) raise InvalidConfiguration, 'API key private key is not set' unless configuration.api_key_private_key raise InvalidConfiguration, 'API key name is not set' unless configuration.api_key_name 'Successfully configured Coinbase SDK' end |
.default_user ⇒ Coinbase::User
Returns the default user.
91 92 93 |
# File 'lib/coinbase.rb', line 91 def self.default_user @default_user ||= load_default_user end |
.load_default_user ⇒ Coinbase::User
Loads the default user.
111 112 113 114 115 |
# File 'lib/coinbase.rb', line 111 def self.load_default_user users_api = Coinbase::Client::UsersApi.new(configuration.api_client) user_model = users_api.get_current_user Coinbase::User.new(user_model) end |
.normalize_network(network_sym) ⇒ String
Converts a network symbol to a string, replacing underscores with hyphens.
105 106 107 |
# File 'lib/coinbase.rb', line 105 def self.normalize_network(network_sym) network_sym.to_s.gsub(/_/, '-') end |
.to_sym(value) ⇒ Symbol
Converts a string to a symbol, replacing hyphens with underscores.
98 99 100 |
# File 'lib/coinbase.rb', line 98 def self.to_sym(value) value.to_s.gsub('-', '_').to_sym end |
.use_server_signer? ⇒ bool
Returns whether to use a server signer to manage private keys.
129 130 131 |
# File 'lib/coinbase.rb', line 129 def self.use_server_signer? Coinbase.configuration.use_server_signer end |