Interface Wallet

Defines the standard interface for a Cardano wallet. This interface provides dApps with a consistent way to interact with a user's wallet for querying information and requesting transaction creation.

interface Wallet {
    getNetworkMagic: () => Promise<number>;
    getPubDRepKey: () => Promise<string>;
    getRegisteredPubStakeKeys: () => Promise<string[]>;
    getUnregisteredPubStakeKeys: () => Promise<string[]>;
    createTransactionBuilder(): Promise<TransactionBuilder>;
    getBalance(): Promise<Value>;
    getChangeAddress(): Promise<Address>;
    getCollateral(): Promise<UTxO[]>;
    getNetworkId(): Promise<NetworkId>;
    getRewardAddresses(): Promise<RewardAddress[]>;
    getUnspentOutputs(): Promise<UTxO[]>;
    getUnusedAddresses(): Promise<Address[]>;
    getUsedAddresses(): Promise<Address[]>;
    signData(
        address: string | Address,
        payload: string,
    ): Promise<{ key: string; signature: string }>;
    signTransaction(
        txCbor: string,
        partialSign: boolean,
    ): Promise<VkeyWitnessSet>;
    submitTransaction(txCbor: string): Promise<string>;
}

Implemented by

Properties

getNetworkMagic: () => Promise<number>

Returns the "network magic," a unique number identifying the Cardano network.

Type declaration

    • (): Promise<number>
    • Returns Promise<number>

      A promise that resolves to the network magic number (e.g., Mainnet: 764824073, Preprod: 1).

getPubDRepKey: () => Promise<string>

Returns the wallet's active public DRep (Delegated Representative) key.

Type declaration

    • (): Promise<string>
    • Returns Promise<string>

      A promise that resolves to the hex-encoded public DRep key.

getRegisteredPubStakeKeys: () => Promise<string[]>

Returns public stake keys from the wallet that are currently registered for on-chain governance voting.

Type declaration

    • (): Promise<string[]>
    • Returns Promise<string[]>

      A promise that resolves to an array of hex-encoded public stake keys.

getUnregisteredPubStakeKeys: () => Promise<string[]>

Returns public stake keys from the wallet that are NOT yet registered for on-chain governance voting.

Type declaration

    • (): Promise<string[]>
    • Returns Promise<string[]>

      A promise that resolves to an array of hex-encoded public stake keys.

Methods

  • Creates and initializes a new transaction builder with the wallet's current state.

    Returns Promise<TransactionBuilder>

    A promise that resolves to a pre-configured TransactionBuilder instance.

    This method simplifies transaction construction by automatically pre-populating the builder with:

    1. The wallet's available UTxOs as inputs.
    2. The wallet's change address to receive any leftover funds.
    3. The network parameters from the wallet's provider.

    The returned builder is ready for you to add outputs and other transaction details.

  • Returns the total balance of all assets controlled by the wallet.

    Returns Promise<Value>

    A promise that resolves to the wallet's total balance, including Lovelace and any native tokens.

  • Returns a single, unused address suitable for receiving change from a transaction.

    Returns Promise<Address>

    A promise that resolves to a Bech32-encoded change address.

  • Returns a list of UTxOs that are designated as collateral.

    Returns Promise<UTxO[]>

    A promise that resolves to an array of collateral UTxOs.

    Collateral is required for transactions that interact with Plutus smart contracts to cover potential script execution failure fees.

  • Returns the wallet's current network ID.

    Returns Promise<NetworkId>

    A promise that resolves to the network ID (0 for Testnet, 1 for Mainnet).

    This is used to ensure the dApp and wallet are operating on the same network.

  • Returns the wallet's reward addresses, used for receiving staking rewards.

    Returns Promise<RewardAddress[]>

    A promise that resolves to an array of Bech32-encoded reward addresses.

  • Returns a list of all Unspent Transaction Outputs (UTxOs) controlled by the wallet.

    Returns Promise<UTxO[]>

    A promise that resolves to an array of UTxOs.

    UTxOs represent the "coins" or assets in the wallet that are available to be spent.

  • Returns a list of unused addresses for receiving payments.

    Returns Promise<Address[]>

    A promise that resolves to an array of unused, Bech32-encoded addresses.

    Using a fresh address for each transaction can improve user privacy.

  • Returns a list of addresses that have been used in past transactions.

    Returns Promise<Address[]>

    A promise that resolves to an array of used, Bech32-encoded addresses.

  • Requests the user to sign arbitrary data with a specific address, compliant with CIP-8.

    Parameters

    • address: string | Address

      The Bech32-encoded address to sign with.

    • payload: string

      The hex-encoded data payload to be signed.

    Returns Promise<{ key: string; signature: string }>

    A promise that resolves to the signature and public key.

    This is useful for proving ownership of an address without creating a blockchain transaction.

  • Requests the user to sign a given transaction.

    Parameters

    • txCbor: string

      The transaction to be signed, provided as a CBOR hex string.

    • partialSign: boolean

      If true, the wallet will only add its witness and not require all signatures to be present. This is for multi-signature transactions.

    Returns Promise<VkeyWitnessSet>

    A promise that resolves to the CBOR hex string of the transaction witness set.

  • Submits a fully signed transaction to the blockchain through the wallet's provider.

    Parameters

    • txCbor: string

      The fully signed transaction, provided as a CBOR hex string.

    Returns Promise<string>

    A promise that resolves to the transaction ID (hash).