Skip to main content

WalletHelper

export interface WalletHelper<W extends ReadonlyWallet> {
  allAddresses: Promise<Address[]>
  baseAddress: Promise<Address>
  calcBalance(): Promise<Value>
  changeAddress: Promise<Address>
  collateral: Promise<TxInput[]>
  isMainnet(): Promise<boolean>
  isOwnAddress(addr: Address): Promise<boolean>
  isOwnPubKeyHash(pkh: PubKeyHash): Promise<boolean>
  refUtxo: Promise<undefined | TxInput>
  selectCollateral(amount?: bigint): Promise<TxInput>
  selectUtxo(value: Value): Promise<TxInput>
  selectUtxos(
    amount: Value,
    coinSelection?: CoinSelection<SpendingCredential>
  ): Promise<TxInput[]>
  signData: W extends Wallet
    ? (
      addr: ShelleyAddress<PubKeyHash>,
      data: BytesLike
    ) => Promise<{
      key: PubKey
      signature: Cip30CoseSign1
    }>
    : never
  signTx: W extends Wallet
    ? (tx: Tx) => Promise<Signature[]>
    : never
  stakingAddresses: Promise<StakingAddress[]>
  submitTx: W extends Wallet
    ? (tx: Tx) => Promise<TxId>
    : never
  toJsonSafe(): Promise<OfflineWalletJsonSafe>
  toOfflineWallet(): Promise<OfflineWallet>
  unusedAddresses: Promise<Address[]>
  usedAddresses: Promise<Address[]>
  utxos: Promise<TxInput[]>
  wallet: W
}
High-level helper for Wallet instances.

Properties

allAddresses

allAddresses: Promise<Address[]>
Concatenation of usedAddresses and unusedAddresses.

baseAddress

baseAddress: Promise<Address>
First Address in allAddresses. Throws an error if there aren't any addresses.

calcBalance

calcBalance(): Promise<Value>
Sums the values of all the utxos.

changeAddress

changeAddress: Promise<Address>
First Address in unusedAddresses (falls back to last Address in usedAddresses if unusedAddresses is empty or not defined).

collateral

collateral: Promise<TxInput[]>
Returns a list of utxos suitable for use as collateral

isMainnet

isMainnet(): Promise<boolean>
Returns true if the wallet is connected to the mainnet.

isOwnAddress

isOwnAddress(addr: Address): Promise<boolean>
Returns true if the PubKeyHash in the given Address is controlled by the wallet.

isOwnPubKeyHash

isOwnPubKeyHash(pkh: PubKeyHash): Promise<boolean>
Returns true if the given PubKeyHash is controlled by the wallet.

refUtxo

refUtxo: Promise<undefined | TxInput>
First UTxO in utxos. Can be used to distinguish between preview and preprod networks.

selectCollateral

selectCollateral(amount?: bigint): Promise<TxInput>
Picks a single UTxO intended as collateral. The amount defaults to 2 Ada, which should cover most things

selectUtxo

selectUtxo(value: Value): Promise<TxInput>
Returns only a single utxo. Throws an error if a UTxO containing the given value isn't found.

selectUtxos

selectUtxos(
  amount: Value,
  coinSelection?: CoinSelection<SpendingCredential>
): Promise<TxInput[]>
Pick a number of UTxOs needed to cover a given Value. The default coin selection strategy is to pick the smallest first.

signData

signData: W extends Wallet
  ? (
    addr: ShelleyAddress<PubKeyHash>,
    data: BytesLike
  ) => Promise<{
    key: PubKey
    signature: Cip30CoseSign1
  }>
  : never
Signs a message, returning an object containing the Signature that can be used to verify/authenticate the message later. Only available if the underlying wallet isn't a ReadonlyWallet

signTx

signTx: W extends Wallet
  ? (tx: Tx) => Promise<Signature[]>
  : never
Signs a transaction, returning a list of signatures needed for submitting a valid transaction. Only available if the underlying wallet isn't a ReadonlyWallet

stakingAddresses

stakingAddresses: Promise<StakingAddress[]>
Returns a list of the reward addresses.

submitTx

submitTx: W extends Wallet
  ? (tx: Tx) => Promise<TxId>
  : never
Submits a transaction to the blockchain and returns the id of that transaction upon success. Only available if the underlying wallet isn't a ReadonlyWallet

toJsonSafe

toJsonSafe(): Promise<OfflineWalletJsonSafe>

toOfflineWallet

toOfflineWallet(): Promise<OfflineWallet>

unusedAddresses

unusedAddresses: Promise<Address[]>
Returns a list of unique unused addresses which can be used to send UTxOs to with increased anonimity.

usedAddresses

usedAddresses: Promise<Address[]>
Returns a list of addresses which already contain UTxOs.

utxos

utxos: Promise<TxInput[]>
Uses the fallback if the list returned from underlying wallet is empty.

wallet

wallet: W
Returns the underlying wallet