Skip to main content

Wallets

A wallet is a collection of addresses on a network. Wallets come with a single default address.

Each address in a wallet can hold a balance of one or more assets. Wallets can create new addresses, list their addresses, list their balances and transfer assets to other addresses or wallets.

Wallets are created on a specific network. The Coinbase Platform SDK only supports Base Sepolia at this time. Use a faucet to obtain funds on your testnet wallet. Do not use the current version of our SDK to hold funds on mainnet.

Wallets created by the Platform SDK are developer custodied, described below. Over time, the Platform SDK will introduce methods to create wallets of different custodial types.

Custodial Types

A wallet’s assets are controlled by the custodian via the private key. Think of a private key as the password to a wallet. See What is a private key. Private keys cannot be changed.

Custodians can be developers (e.g., you), end-users (e.g., your customers), or Coinbase.

Custody TypeDescription
Developer custodiedDeveloper of app (you) custodies the assets. Platform SDK helps you create developer custodied wallets.
End-user custodiedEnd-users (your customers) custody the funds and control their movements.

Creating a wallet

To create a wallet, call create_wallet on the user object:

w = u.create_wallet

A wallet starts with a single default_address. You can also create more addresses in the wallet, and list them:

# Get the default_address in the wallet.
a1 = w.default_address

# Create another address in the wallet.
a2 = w.create_address

# List the two addresses in the wallet.
w.list_addresses

Importing and Exporting wallets

When you create a wallet, the Platform SDK initializes a hexadecimal number known as a seed. The seed is used to derive all of the private keys in the wallet, and provides access to spend the assets in the wallet. The seed constitutes one portion of the wallet data required to re-instantiate a wallet.

Because the Platform SDK currently supports only developer custodied wallets, you (the developer) are responsible for securely storing this wallet data required to re-instantiate wallets. For example, you may choose to store this data in an encrypted database.

The following code demonstrates how to export and import the data required to re-instantiate a wallet.

# Create a wallet with one address by default.
w1 = u.create_wallet

# Export the data required to re-instantiate the wallet.
data = w1.export

# At this point, you should implement your own "store" method to securely persist
# the data required to re-instantiate the wallet at a later time.
store(data)

# The wallet can be re-instantiated using the exported data.
# w2 will be equivalent to w1.
w2 = u.import_wallet(data)

Persisting Wallet Data Locally

caution

For convenience, we provide a save_wallet method that stores the Wallet data in your local file system. This is an insecure method of storing wallet seeds and should only be used for development purposes.

u.save_wallet(w3)

To encrypt the saved data, set encrypt to true. Note that your CDP API key also serves as the encryption key for the data persisted locally. To re-instantiate wallets with encrypted data, ensure that your SDK is configured with the same API key when invoking save_wallet and load_wallets.

u.save_wallet(w3, encrypt: true)

To import wallets that were persisted to your local file system using save_wallet, use the below code.

wallets = u.load_wallets

SDK Documentation

Refer to the Wallet class SDK docs for a full list of supported methods.

Was this helpful?