Module: Coinbase
- Defined in:
- lib/coinbase.rb,
lib/coinbase/user.rb,
lib/coinbase/asset.rb,
lib/coinbase/wallet.rb,
lib/coinbase/address.rb,
lib/coinbase/network.rb,
lib/coinbase/transfer.rb,
lib/coinbase/constants.rb,
lib/coinbase/middleware.rb,
lib/coinbase/balance_map.rb,
lib/coinbase/authenticator.rb
Overview
The Coinbase SDK.
Defined Under Namespace
Modules: Client, Middleware Classes: Address, Asset, Authenticator, BalanceMap, Configuration, InvalidConfiguration, Network, Transfer, User, Wallet
Constant Summary collapse
- ETH =
The Assets supported on Base Sepolia by the Coinbase SDK.
Asset.new(network_id: :base_sepolia, asset_id: :eth, display_name: 'Ether')
- USDC =
Asset.new(network_id: :base_sepolia, asset_id: :usdc, display_name: 'USD Coin', address_id: '0x036CbD53842c5426634e7929541eC2318f3dCF7e')
- BASE_SEPOLIA =
The Base Sepolia Network.
Network.new( network_id: :base_sepolia, display_name: 'Base Sepolia', protocol_family: :evm, is_testnet: true, assets: [ETH, USDC], native_asset_id: :eth, chain_id: 84_532 )
- WEI_PER_ETHER =
The amount of Wei per Ether.
1_000_000_000_000_000_000- WEI_PER_GWEI =
The amount of Wei per Gwei.
1_000_000_000- GWEI_PER_ETHER =
The amount of Gwei per Ether.
1_000_000_000- ATOMIC_UNITS_PER_USDC =
The amount of atomic units of USDC per USDC.
1_000_000- SUPPORTED_ASSET_IDS =
A map of supported Asset IDs.
{ eth: true, # Ether, the native asset of most EVM networks. gwei: true, # A medium denomination of Ether, typically used in gas prices. wei: true, # The smallest denomination of Ether. usdc: true # USD Coin, a stablecoin pegged to the US Dollar. }.freeze
Class Method Summary collapse
- .configuration ⇒ Object
- .configure {|configuration| ... } ⇒ Object
-
.default_user ⇒ Coinbase::User
Returns the default user.
- .load_default_user ⇒ Object
-
.to_balance_map(address_balance_list) ⇒ BalanceMap
Converts a Coinbase::Client::AddressBalanceList to a BalanceMap.
-
.to_sym(value) ⇒ Symbol
Converts a string to a symbol, replacing hyphens with underscores.
Class Method Details
.configuration ⇒ Object
19 20 21 |
# File 'lib/coinbase.rb', line 19 def self.configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
23 24 25 26 27 28 |
# File 'lib/coinbase.rb', line 23 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 end |
.default_user ⇒ Coinbase::User
Returns the default user.
53 54 55 |
# File 'lib/coinbase.rb', line 53 def self.default_user @default_user ||= load_default_user end |
.load_default_user ⇒ Object
85 86 87 88 89 |
# File 'lib/coinbase.rb', line 85 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 |
.to_balance_map(address_balance_list) ⇒ BalanceMap
Converts a Coinbase::Client::AddressBalanceList to a BalanceMap.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/coinbase.rb', line 67 def self.to_balance_map(address_balance_list) balances = {} address_balance_list.data.each do |balance| asset_id = Coinbase.to_sym(balance.asset.asset_id.downcase) amount = if asset_id == :eth BigDecimal(balance.amount) / BigDecimal(Coinbase::WEI_PER_ETHER) elsif asset_id == :usdc BigDecimal(balance.amount) / BigDecimal(Coinbase::ATOMIC_UNITS_PER_USDC) else BigDecimal(balance.amount) end balances[asset_id] = amount end BalanceMap.new(balances) end |
.to_sym(value) ⇒ Symbol
Converts a string to a symbol, replacing hyphens with underscores.
60 61 62 |
# File 'lib/coinbase.rb', line 60 def self.to_sym(value) value.to_s.gsub('-', '_').to_sym end |