WalletUnlocked provides the functionalities for an unlocked wallet.

Hierarchy (view full)

Constructors

Properties

_connector?: FuelConnector

The connector for use with external wallets

_provider?: Provider

The provider used to interact with the network.

address: Address

The address associated with the account.

signer: (() => Signer)

A function that returns the wallet's signer.

defaultPath: string = "m/44'/1179993420'/0'/0/0"

Default HDWallet path.

Accessors

  • get privateKey(): string
  • Gets the private key of the wallet.

    Returns string

    The private key of the wallet.

  • get provider(): Provider
  • The provider used to interact with the network.

    Returns Provider

    A Provider instance.

    FuelError if the provider is not set.

  • set provider(provider): void
  • Sets the provider for the account.

    Parameters

    Returns void

  • get publicKey(): string
  • Gets the public key of the wallet.

    Returns string

Methods

  • Assembles transactions for consolidating base asset coins into fewer UTXOs.

    This method splits the provided coins into batches and creates transaction requests to consolidate them. It calculates the necessary fee and sets up the transactions to be submitted either in parallel (default) or sequentially.

    Parameters

    Returns Promise<{
        submitAll: SubmitAllCallback;
        totalFeeCost: BN;
        txs: ScriptTransactionRequest[];
    }>

    An object containing the assembled transactions, the total fee cost, and a callback to submit all transactions.

  • Transfers multiple amounts of a token to multiple recipients.

    Parameters

    • transferParams: TransferParams[]

      An array of TransferParams objects representing the transfers to be made.

    • txParams: TxParamsType = {}

      Optional transaction parameters.

    Returns Promise<TransactionResponse>

    A promise that resolves to a TransactionResponse object representing the transaction result.

  • Changes the provider connection for the account.

    Parameters

    Returns Provider

    The updated Provider instance.

  • Consolidates base asset UTXOs into fewer, larger ones.

    Retrieves a limited number of base asset coins (as defined by Provider.RESOURCES_PAGE_SIZE_LIMIT), assembles consolidation transactions, and submits them to the network.

    Note: This method currently supports only the base asset.

    Parameters

    • params: ConsolidateCoins

      The parameters for coin consolidation, including the asset ID, mode, and output number.

    Returns Promise<SubmitAllCallbackResponse>

    A promise that resolves to the response of the submitted transactions.

    Will throw an error if the asset is not a base asset as non-base asset consolidation is not implemented.

  • A helper that creates a transfer transaction request and returns it.

    Parameters

    • destination: string | Address

      The address of the destination.

    • amount: BigNumberish

      The amount of coins to transfer.

    • OptionalassetId: BytesLike

      The asset ID of the coins to transfer (optional).

    • txParams: TxParamsType = {}

      The transaction parameters (optional).

    Returns Promise<ScriptTransactionRequest>

    A promise that resolves to the prepared transaction request.

  • Encrypts an unlocked wallet with a password.

    Parameters

    • password: string

      the password to encrypt the wallet with.

    Returns Promise<string>

    • the encrypted wallet.
  • Generates an array of fake resources based on the provided coins.

    Parameters

    • coins: FakeResources[]

      An array of FakeResources objects representing the coins.

    Returns Resource[]

    An array of Resource objects with generated properties.

  • Retrieves the balance of the account for the given asset.

    Parameters

    • OptionalassetId: BytesLike

      The asset ID to check the balance for (optional).

    Returns Promise<BN>

    A promise that resolves to the balance amount.

  • Retrieves coins owned by the account.

    Parameters

    • OptionalassetId: BytesLike

      The asset ID of the coins to retrieve (optional).

    • OptionalpaginationArgs: CursorPaginationArgs

    Returns Promise<GetCoinsResponse>

    A promise that resolves to an array of Coins.

  • Retrieves resources satisfying the spend query for the account.

    Parameters

    Returns Promise<Resource[]>

    A promise that resolves to an array of Resources.

  • Locks the wallet and returns an instance of WalletLocked.

    Returns WalletLocked

    An instance of WalletLocked.

  • Populates the witness signature for a transaction and sends it to the network using provider.sendTransaction.

    Parameters

    Returns Promise<TransactionResponse>

    A promise that resolves to the TransactionResponse object.

  • Signs a message with the wallet's private key.

    Parameters

    Returns Promise<string>

    A promise that resolves to the signature as a ECDSA 64 bytes string.

  • Signs a transaction with the wallet's private key.

    Parameters

    Returns Promise<string>

    A promise that resolves to the signature as a ECDSA 64 bytes string.

  • Populates the witness signature for a transaction and sends a call to the network using provider.dryRun.

    Parameters

    Returns Promise<CallResult>

    A promise that resolves to the CallResult object.

  • Transfers coins to a destination address.

    Parameters

    • destination: string | Address

      The address of the destination.

    • amount: BigNumberish

      The amount of coins to transfer.

    • OptionalassetId: BytesLike

      The asset ID of the coins to transfer (optional).

    • txParams: TxParamsType = {}

      The transaction parameters (optional).

    Returns Promise<TransactionResponse>

    A promise that resolves to the transaction response.

  • Create a Wallet Unlocked from an encrypted JSON.

    Parameters

    • jsonWallet: string

      The encrypted JSON keystore.

    • password: string

      The password to decrypt the JSON.

    • Optionalprovider: Provider

      A Provider instance (optional).

    Returns Promise<WalletUnlocked>

    An unlocked wallet instance.

  • Create a Wallet Unlocked from an extended key.

    Parameters

    • extendedKey: string

      The extended key.

    • Optionalprovider: Provider

      A Provider instance (optional).

    Returns WalletUnlocked

    An instance of WalletUnlocked.

  • Create a Wallet Unlocked from a mnemonic phrase.

    Parameters

    • mnemonic: string

      The mnemonic phrase.

    • Optionalpath: string

      The derivation path (optional).

    • Optionalpassphrase: BytesLike

      The passphrase for the mnemonic (optional).

    • Optionalprovider: Provider

      A Provider instance (optional).

    Returns WalletUnlocked

    An instance of WalletUnlocked.

  • Create a Wallet Unlocked from a seed.

    Parameters

    • seed: string

      The seed phrase.

    • Optionalpath: string

      The derivation path (optional).

    • Optionalprovider: Provider

      A Provider instance (optional).

    Returns WalletUnlocked

    An instance of WalletUnlocked.

  • Generate a new Wallet Unlocked with a random key pair.

    Parameters

    • OptionalgenerateOptions: GenerateOptions

      Options to customize the generation process (optional).

    Returns WalletUnlocked

    An instance of WalletUnlocked.