Class: Coinbase::User

Inherits:
Object
  • Object
show all
Defined in:
lib/coinbase/user.rb

Overview

A representation of a User. Users have Wallets, which can hold balances of Assets. Access the default User through Coinbase#default_user.

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ User

Returns a new User object. Do not use this method directly. Instead, use Coinbase#default_user.

Parameters:



12
13
14
# File 'lib/coinbase/user.rb', line 12

def initialize(model)
  @model = model
end

Instance Method Details

#create_walletCoinbase::Wallet

Creates a new Wallet belonging to the User.

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/coinbase/user.rb', line 24

def create_wallet
  create_wallet_request = {
    wallet: {
      # TODO: Don't hardcode this.
      network_id: 'base-sepolia'
    }
  }
  opts = { create_wallet_request: create_wallet_request }

  model = wallets_api.create_wallet(opts)

  Wallet.new(model)
end

#import_wallet(data) ⇒ Coinbase::Wallet

Imports a Wallet belonging to the User.

Parameters:

Returns:



41
42
43
44
45
# File 'lib/coinbase/user.rb', line 41

def import_wallet(data)
  model = wallets_api.get_wallet(data.wallet_id)
  address_count = addresses_api.list_addresses(model.id).total_count
  Wallet.new(model, seed: data.seed, address_count: address_count)
end

#list_wallet_idsArray<String>

Lists the IDs of the Wallets belonging to the User.

Returns:

  • (Array<String>)

    the IDs of the Wallets belonging to the User



49
50
51
52
# File 'lib/coinbase/user.rb', line 49

def list_wallet_ids
  wallets = wallets_api.list_wallets
  wallets.data.map(&:id)
end

#user_idString

Returns the User ID.

Returns:

  • (String)

    the User ID



18
19
20
# File 'lib/coinbase/user.rb', line 18

def user_id
  @model.id
end