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/pagination.rb,
lib/coinbase/balance_map.rb,
lib/coinbase/transaction.rb,
lib/coinbase/authenticator.rb,
lib/coinbase/server_signer.rb,
lib/coinbase/staking_reward.rb,
lib/coinbase/staking_operation.rb,
lib/coinbase/faucet_transaction.rb,
lib/coinbase/address/wallet_address.rb,
lib/coinbase/address/external_address.rb
Overview
The Coinbase SDK.
Defined Under Namespace
Modules: Client, Middleware, Pagination Classes: APIError, Address, AlreadyExistsError, Asset, Authenticator, Balance, BalanceMap, Configuration, ExternalAddress, FaucetLimitReachedError, FaucetTransaction, InsufficientFundsError, InternalError, InvalidAddressError, InvalidAddressIDError, InvalidAmountError, InvalidAssetIDError, InvalidConfiguration, InvalidDestinationError, InvalidLimitError, InvalidNetworkIDError, InvalidPageError, InvalidSignedPayloadError, InvalidTransferIDError, InvalidTransferStatusError, InvalidWalletError, InvalidWalletIDError, MalformedRequestError, Network, NetworkFeatureUnsupportedError, NotFoundError, ResourceExhaustedError, ServerSigner, StakingOperation, StakingReward, Trade, Transaction, Transfer, UnauthorizedError, UnimplementedError, UnsupportedAssetError, User, Wallet, WalletAddress
Constant Summary collapse
- ERROR_CODE_TO_ERROR_CLASS =
{ 'unimplemented' => UnimplementedError, 'unauthorized' => UnauthorizedError, '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.
-
.configured? ⇒ bool
Returns whether the SDK is configured.
-
.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.
124 125 126 127 128 129 130 |
# File 'lib/coinbase.rb', line 124 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.
33 34 35 |
# File 'lib/coinbase.rb', line 33 def self.configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ String
Configures the Coinbase SDK.
39 40 41 42 43 44 45 46 |
# File 'lib/coinbase.rb', line 39 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.
52 53 54 55 56 57 58 59 |
# File 'lib/coinbase.rb', line 52 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 |
.configured? ⇒ bool
Returns whether the SDK is configured.
140 141 142 |
# File 'lib/coinbase.rb', line 140 def self.configured? !Coinbase.configuration.api_key_name.nil? && !Coinbase.configuration.api_key_private_key.nil? end |
.default_user ⇒ Coinbase::User
Returns the default user.
96 97 98 |
# File 'lib/coinbase.rb', line 96 def self.default_user @default_user ||= load_default_user end |
.load_default_user ⇒ Coinbase::User
Loads the default user.
116 117 118 119 120 |
# File 'lib/coinbase.rb', line 116 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.
110 111 112 |
# File 'lib/coinbase.rb', line 110 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.
103 104 105 |
# File 'lib/coinbase.rb', line 103 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.
134 135 136 |
# File 'lib/coinbase.rb', line 134 def self.use_server_signer? Coinbase.configuration.use_server_signer end |