# Wallet | xrpl
Documentation for xrpl

# Class Wallet

A utility for deriving a wallet composed of a keypair (publicKey/privateKey). A wallet can be derived from either a seed, mnemonic, or entropy (array of random numbers). It provides functionality to sign/verify transactions offline.

### Example

    // Derive a wallet from a base58 encoded seed.
    const seedWallet = Wallet.fromSeed('ssZkdwURFMBXenJPbrpE14b6noJSu')
    console.log(seedWallet)
    // Wallet {
    // publicKey: '02FE9932A9C4AA2AC9F0ED0F2B89302DE7C2C95F91D782DA3CF06E64E1C1216449',
    // privateKey: '00445D0A16DD05EFAF6D5AF45E6B8A6DE4170D93C0627021A0B8E705786CBCCFF7',
    // classicAddress: 'rG88FVLjvYiQaGftSa1cKuE2qNx7aK5ivo',
    // seed: 'ssZkdwURFMBXenJPbrpE14b6noJSu'
    // }.

    // Sign a JSON Transaction
     const signed = seedWallet.signTransaction({
         TransactionType: 'Payment',
         Account: 'rG88FVLjvYiQaGftSa1cKuE2qNx7aK5ivo'
         ...........
    }).

    console.log(signed)
    // '1200007321......B01BE1DFF3'.
    console.log(decode(signed))
    // {
    //   TransactionType: 'Payment',
    //   SigningPubKey: '02FE9932A9C4AA2AC9F0ED0F2B89302DE7C2C95F91D782DA3CF06E64E1C1216449',
    //   TxnSignature: '3045022100AAD......5B631ABD21171B61B07D304',
    //   Account: 'rG88FVLjvYiQaGftSa1cKuE2qNx7aK5ivo'
    //   ...........
    // }

#### Hierarchy

- Wallet

- Defined in packages/xrpl/src/Wallet/index.ts:79

#####
Index

### Constructors

constructor

### Properties

classicAddress
privateKey
publicKey
seed?
fromSecret

### Accessors

address

### Methods

getXAddress
sign
verifyTransaction
deriveWallet
fromEntropy
fromMnemonic
fromRFC1751Mnemonic
fromSeed
generate

## Constructors

### constructor

- new Wallet(publicKey: string, privateKey: string, opts?: {
  masterAddress?: string;
  seed?: string;
  }): Wallet

- Creates a new Wallet.

  #### Parameters

  - ##### publicKey: string

    The public key for the account.

  - ##### privateKey: string

    The private key used for signing transactions for the account.

  - ##### opts: {
    masterAddress?: string;
    seed?: string;
    } = {}

    (Optional) Options to initialize a Wallet.

    - ##### `Optional` masterAddress?: string

      Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.

    - ##### `Optional` seed?: string

      The seed used to derive the account keys.

  #### Returns Wallet

  - Defined in packages/xrpl/src/Wallet/index.ts:94

## Properties

### `Readonly` classicAddress

classicAddress: string

- Defined in packages/xrpl/src/Wallet/index.ts:82

### `Readonly` privateKey

privateKey: string

- Defined in packages/xrpl/src/Wallet/index.ts:81

### `Readonly` publicKey

publicKey: string

- Defined in packages/xrpl/src/Wallet/index.ts:80

### `Optional` `Readonly` seed

seed?: string

- Defined in packages/xrpl/src/Wallet/index.ts:83

### `Static` fromSecret

fromSecret: ((seed: string, opts?: {
algorithm?: ECDSA;
masterAddress?: string;
}) => Wallet ) = Wallet.fromSeed

#### Type declaration

- - (seed: string, opts?: {
    algorithm?: ECDSA;
    masterAddress?: string;
    }): Wallet

  - Derives a wallet from a secret (AKA a seed).

    ### Returns

    A Wallet derived from a secret (AKA a seed).

    #### Parameters

    - ##### seed: string

    - ##### opts: {
      algorithm?: ECDSA;
      masterAddress?: string;
      } = {}

      (Optional) Options to derive a Wallet.

      - ##### `Optional` algorithm?: ECDSA

        The digital signature algorithm to generate an address for.

      - ##### `Optional` masterAddress?: string

        Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.

    #### Returns Wallet

- Defined in packages/xrpl/src/Wallet/index.ts:167

## Accessors

### address

- get address(): string

- Alias for wallet.classicAddress.

  ### Returns

  The wallet's classic address.

  #### Returns string

  - Defined in packages/xrpl/src/Wallet/index.ts:115

## Methods

### getXAddress

- getXAddress(tag?: number | false, isTestnet?: boolean): string

- Gets an X-address in Testnet/Mainnet format.

  ### Returns

  An X-address.

  #### Parameters

  - ##### tag: number | false = false

    A tag to be included within the X-address.

  - ##### isTestnet: boolean = false

    A boolean to indicate if X-address should be in Testnet (true) or Mainnet (false) format.

  #### Returns string

  - Defined in packages/xrpl/src/Wallet/index.ts:450

### sign

- sign(this: Wallet, transaction: Transaction, multisign?: string | boolean): {
  hash: string;
  tx_blob: string;
  }

- Signs a transaction offline.

  ### Example

      const { Client, Wallet } = require('xrpl')
      const client = new Client('wss://s.altnet.rippletest.net:51233')

      async function signTransaction() {
        await client.connect()
        const { balance: balance1, wallet: wallet1 } = client.fundWallet()
        const { balance: balance2, wallet: wallet2 } = client.fundWallet()

        const transaction = {
          TransactionType: 'Payment',
          Account: wallet1.address,
          Destination: wallet2.address,
          Amount: '10'
        }

        try {
          await client.autofill(transaction)
          const { tx_blob: signed_tx_blob, hash} = await wallet1.sign(transaction)
          console.log(signed_tx_blob)
        } catch (error) {
          console.error(`Failed to sign transaction: ${error}`)
        }
        const result = await client.submit(signed_tx_blob)
        await client.disconnect()
      }

      signTransaction()

  In order for a transaction to be validated, it must be signed by the account sending the transaction to prove That the owner is actually the one deciding to take that action.

  In this example, we created, signed, and then submitted a transaction to testnet. You may notice that the Output of `sign` includes a `tx_blob` and a `hash`, both of which are needed to submit & verify the results. Note: If you pass a `Wallet` to `client.submit` or `client.submitAndWait` it will do signing like this under the hood.

  `tx_blob` is a binary representation of a transaction on the XRP Ledger. It's essentially a byte array that encodes all of the data necessary to execute the transaction, including the source address, the destination address, the amount, and any additional fields required for the specific transaction type.

  `hash` is a unique identifier that's generated from the signed transaction data on the XRP Ledger. It's essentially A cryptographic digest of the signed transaction blob, created using a hash function. The signed transaction hash is Useful for identifying and tracking specific transactions on the XRP Ledger. It can be used to query transaction Information, verify the authenticity of a transaction, and detect any tampering with the transaction data.

  ### Returns

  A signed transaction.

  ### Throws

  ValidationError if the transaction is already signed or does not encode/decode to same result.

  ### Throws

  XrplError if the issued currency being signed is XRP ignoring case.

  #### Parameters

  - ##### this: Wallet

    Wallet instance.

  - ##### transaction: Transaction

    A transaction to be signed offline.

  - ##### `Optional` multisign: string | boolean

    Specify true/false to use multisign or actual address (classic/x-address) to make multisign tx request.

  #### Returns {
  hash: string;
  tx_blob: string;
  }

  - ##### hash: string

  - ##### tx_blob: string

  - Defined in packages/xrpl/src/Wallet/index.ts:362

### verifyTransaction

- verifyTransaction(signedTransaction: string | Transaction ): boolean

- Verifies a signed transaction offline.

  ### Returns

  Returns true if a signedTransaction is valid.

  #### Parameters

  - ##### signedTransaction: string | Transaction

    A signed transaction (hex string of signTransaction result) to be verified offline.

  #### Returns boolean

  - Defined in packages/xrpl/src/Wallet/index.ts:433

### `Static` `Private` deriveWallet

- deriveWallet(seed: string, opts?: {
  algorithm?: ECDSA;
  masterAddress?: string;
  }): Wallet

- Derive a Wallet from a seed.

  ### Returns

  A Wallet derived from the seed.

  #### Parameters

  - ##### seed: string

    The seed used to derive the wallet.

  - ##### opts: {
    algorithm?: ECDSA;
    masterAddress?: string;
    } = {}

    (Optional) Options to derive a Wallet.

    - ##### `Optional` algorithm?: ECDSA

      The digital signature algorithm to generate an address for.

    - ##### `Optional` masterAddress?: string

      Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.

  #### Returns Wallet

  - Defined in packages/xrpl/src/Wallet/index.ts:291

### `Static` fromEntropy

- fromEntropy(entropy: number[] | Uint8Array, opts?: {
  algorithm?: ECDSA;
  masterAddress?: string;
  }): Wallet

- Derives a wallet from an entropy (array of random numbers).

  ### Returns

  A Wallet derived from an entropy.

  #### Parameters

  - ##### entropy: number[] | Uint8Array

    An array of random numbers to generate a seed used to derive a wallet.

  - ##### opts: {
    algorithm?: ECDSA;
    masterAddress?: string;
    } = {}

    (Optional) Options to derive a Wallet.

    - ##### `Optional` algorithm?: ECDSA

      The digital signature algorithm to generate an address for.

    - ##### `Optional` masterAddress?: string

      Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.

  #### Returns Wallet

  - Defined in packages/xrpl/src/Wallet/index.ts:178

### `Static` fromMnemonic

- fromMnemonic(mnemonic: string, opts?: {
  algorithm?: ECDSA;
  derivationPath?: string;
  masterAddress?: string;
  mnemonicEncoding?: "bip39" | "rfc1751";
  }): Wallet

- Derives a wallet from a bip39 or RFC1751 mnemonic (Defaults to bip39).

  ### Deprecated

  since version 2.6.1. Will be deleted in version 3.0.0. This representation is currently deprecated in rippled. You should use another method to represent your keys such as a seed or public/private keypair.

  ### Returns

  A Wallet derived from a mnemonic.

  ### Throws

  ValidationError if unable to derive private key from mnemonic input.

  #### Parameters

  - ##### mnemonic: string

    A string consisting of words (whitespace delimited) used to derive a wallet.

  - ##### opts: {
    algorithm?: ECDSA;
    derivationPath?: string;
    masterAddress?: string;
    mnemonicEncoding?: "bip39" | "rfc1751";
    } = {}

    (Optional) Options to derive a Wallet.

    - ##### `Optional` algorithm?: ECDSA

      Only used if opts.mnemonicEncoding is 'rfc1751'. Allows the mnemonic to generate its secp256k1 seed, or its ed25519 seed. By default, it will generate the secp256k1 seed to match the rippled `wallet_propose` default algorithm.

    - ##### `Optional` derivationPath?: string

      The path to derive a keypair (publicKey/privateKey). Only used for bip39 conversions.

    - ##### `Optional` masterAddress?: string

      Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.

    - ##### `Optional` mnemonicEncoding?: "bip39" | "rfc1751"

      If set to 'rfc1751', this interprets the mnemonic as a rippled RFC1751 mnemonic like `wallet_propose` generates in rippled. Otherwise the function defaults to bip39 decoding.

  #### Returns Wallet

  - Defined in packages/xrpl/src/Wallet/index.ts:214

### `Static` `Private` fromRFC1751Mnemonic

- fromRFC1751Mnemonic(mnemonic: string, opts: {
  algorithm?: ECDSA;
  masterAddress?: string;
  }): Wallet

- Derives a wallet from a RFC1751 mnemonic, which is how `wallet_propose` encodes mnemonics.

  ### Returns

  A Wallet derived from a mnemonic.

  #### Parameters

  - ##### mnemonic: string

    A string consisting of words (whitespace delimited) used to derive a wallet.

  - ##### opts: {
    algorithm?: ECDSA;
    masterAddress?: string;
    }

    (Optional) Options to derive a Wallet.

    - ##### `Optional` algorithm?: ECDSA

      The digital signature algorithm to generate an address for.

    - ##### `Optional` masterAddress?: string

      Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.

  #### Returns Wallet

  - Defined in packages/xrpl/src/Wallet/index.ts:263

### `Static` fromSeed

- fromSeed(seed: string, opts?: {
  algorithm?: ECDSA;
  masterAddress?: string;
  }): Wallet

- Derives a wallet from a seed.

  ### Returns

  A Wallet derived from a seed.

  #### Parameters

  - ##### seed: string

    A string used to generate a keypair (publicKey/privateKey) to derive a wallet.

  - ##### opts: {
    algorithm?: ECDSA;
    masterAddress?: string;
    } = {}

    (Optional) Options to derive a Wallet.

    - ##### `Optional` algorithm?: ECDSA

      The digital signature algorithm to generate an address for.

    - ##### `Optional` masterAddress?: string

      Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.

  #### Returns Wallet

  - Defined in packages/xrpl/src/Wallet/index.ts:147

### `Static` generate

- generate(algorithm?: ECDSA): Wallet

- `generate()` creates a new random Wallet. In order to make this a valid account on ledger, you must Send XRP to it. On test networks that can be done with "faucets" which send XRP to any account which asks For it. You can call `client.fundWallet()` in order to generate credentials and fund the account on test networks.

  ### Example

      const { Wallet } = require('xrpl')
      const wallet = Wallet.generate()

  ### Returns

  A new Wallet derived from a generated seed.

  #### Parameters

  - ##### algorithm: ECDSA = DEFAULT_ALGORITHM

    The digital signature algorithm to generate an address for.

  #### Returns Wallet

  - Defined in packages/xrpl/src/Wallet/index.ts:133

Generated using TypeDoc