# Use Tickets

[Tickets](/docs/concepts/accounts/tickets) provide a way to send transactions out of the normal order. This tutorial walks through the steps of creating a Ticket, then using it to send another transaction.

## Prerequisites

script
script
This page provides JavaScript examples that use the [xrpl.js](https://js.xrpl.org/) library. See [Get Started Using JavaScript](/docs/tutorials/get-started/get-started-javascript) for setup instructions.

Since JavaScript works in the web browser, you can read along and use the interactive steps without any setup.

## Steps

This tutorial is divided into a few phases:

- (Steps 1-2) **Setup:** You need an XRP Ledger address and secret. For production, you can use the same address and secret consistently. For this tutorial, you can generate new test credentials as needed. You also need to be connected to the network.
- (Steps 3-6) **Create Tickets:** Send a transaction to set aside some Tickets.
- (Optional) **Intermission:** After creating Tickets, you can send various other transactions at any time before, during, and after the following steps.
- (Steps 7-10) **Use Ticket:** Use one of your set-aside Tickets to send a transaction. You can repeat these steps while skipping the previous parts as long as you have at least one Ticket remaining to use.


### 1. Get Credentials

To transact on the XRP Ledger, you need an address and secret key, and some XRP. For development purposes, you can get these on the [Testnet](/docs/concepts/networks-and-servers/parallel-networks) using the following interface:

Get Testnet credentials

div
Ripple provides the [Testnet and Devnet](/docs/concepts/networks-and-servers/parallel-networks) for testing purposes only, and sometimes resets the state of these test networks along with all balances. As a precaution, **do not** use the same addresses on Testnet/Devnet and Mainnet.

When you're building production-ready software, you should use an existing account, and manage your keys using a [secure signing configuration](/docs/concepts/transactions/secure-signing).

### 2. Connect to Network

You must be connected to the network to submit transactions to it. Since Tickets are only available on Devnet so far, you should connect to a Devnet server. For example:

JavaScript

```js
// Connect to Devnet (since that's where tickets are available)
async function main() {
  const client = new xrpl.Client("wss://s.devnet.rippletest.net:51233")
  await client.connect()
```

The code samples in this tutorial use JavaScript's [`async`/`await` pattern](https://javascript.info/async-await). Since `await` needs to be used from within an `async` function, the remaining code samples are written to continue inside the `main()` function started here. You can also use Promise methods `.then()` and `.catch()` instead of `async`/`await` if you prefer.

For this tutorial, click the following button to connect:

Connect to Testnet

div
strong
Connection status: 
span
Not connected
### 3. Check Sequence Number

Before you create any Tickets, you should check what [Sequence Number](/docs/references/protocol/data-types/basic-data-types#account-sequence) your account is at. You want the current Sequence number for the next step, and the Ticket Sequence numbers it sets aside start from this number.

JavaScript

```js
  // Check Sequence Number -----------------------------------------------------
  const account_info = await client.request({
    "command": "account_info",
    "account": wallet.address
  })
  let current_sequence = account_info.result.account_data.Sequence
```

Check Sequence
Check Sequence Number

div
### 4. Prepare and Sign TicketCreate

Construct a [TicketCreate transaction](/docs/references/protocol/transactions/types/ticketcreate) using the sequence number you determined in the previous step. Use the `TicketCount` field to specify how many Tickets to create. For example, to prepare a transaction that would make 10 Tickets:

JavaScript

```js
  // Prepare and Sign TicketCreate ---------------------------------------------
  const prepared = await client.autofill({
    "TransactionType": "TicketCreate",
    "Account": wallet.address,
    "TicketCount": 10,
    "Sequence": current_sequence
  })
  const signed = wallet.sign(prepared)
  console.log(`Prepared TicketCreate transaction ${signed.hash}`)
```

Record the transaction's hash and `LastLedgerSequence` value so you can [be sure whether or not it got validated](/docs/concepts/transactions/reliable-transaction-submission) later.

Prepare & Sign
Prepare & Sign

div
### 5. Submit TicketCreate

Submit the signed transaction blob that you created in the previous step. For example:

JavaScript

```js
  // Submit TicketCreate -------------------------------------------------------
  const tx = await client.submitAndWait(signed.tx_blob)
  console.log(tx)
```

Submit
Submit

div
### 6. Wait for Validation

Most transactions are accepted into the next ledger version after they're submitted, which means it may take 4-7 seconds for a transaction's outcome to be final. If the XRP Ledger is busy or poor network connectivity delays a transaction from being relayed throughout the network, a transaction may take longer to be confirmed. (For information on how to set an expiration for transactions, see [Reliable Transaction Submission](/docs/concepts/transactions/reliable-transaction-submission).)

JavaScript

```js
  // Wait for Validation -------------------------------------------------------
  // submitAndWait() handles this automatically, but it can take 4-7s.
```

table
tbody
tr
th
Transaction ID:
td
(None)
tr
th
Latest Validated Ledger Index:
td
(Not connected)
tr
th
Ledger Index at Time of Submission:
td
(Not submitted)
tr
th
Transaction 
code
LastLedgerSequence
:
td
(Not prepared)
tr
### (Optional) Intermission

The power of Tickets is that you can carry on with your account's business as usual while you are getting Ticketed transactions ready. When you want to send a transaction using a Ticket, you can do that in parallel with other sending transactions, including ones using different Tickets, and submit a Ticketed transaction at any time. The only constraint is that each Ticket can only be used once.

You can come back here to send Sequenced transactions between or during any of the following steps, without interfering with the success of your Ticketed transaction.

Intermission
Payment
EscrowCreate
AccountSet

div
### 7. Check Available Tickets

When you want to send a Ticketed transaction, you need to know what Ticket Sequence number to use for it. If you've been keeping careful track of your account, you already know which Tickets you have, but if you're not sure, you can use the [account_objects method](/docs/references/http-websocket-apis/public-api-methods/account-methods/account_objects) to look up your available tickets. For example:

JavaScript

```js
  // Check Available Tickets ---------------------------------------------------
  let response = await client.request({
    "command": "account_objects",
    "account": wallet.address,
    "type": "ticket"
  })
  console.log("Available Tickets:", response.result.account_objects)

  // Choose an arbitrary Ticket to use
  use_ticket = response.result.account_objects[0].TicketSequence
```

Check Tickets
Check Tickets

div
You can repeat the steps from here through the end as long as you have Tickets left to be used!

### 8. Prepare Ticketed Transaction

Now that you have a Ticket available, you can prepare a transaction that uses it.

This can be any [type of transaction](/docs/references/protocol/transactions/types) you like. The following example uses a no-op [AccountSet transaction](/docs/references/protocol/transactions/types/accountset) since that doesn't require any other setup in the ledger. Set the `Sequence` field to `0` and include a `TicketSequence` field with the Ticket Sequence number of one of your available Tickets.

JavaScript

```js
  // Prepare and Sign Ticketed Transaction -------------------------------------
  const prepared_t = await client.autofill({
    "TransactionType": "AccountSet",
    "Account": wallet.address,
    "TicketSequence": use_ticket,
    "LastLedgerSequence": null, // Never expire this transaction.
    "Sequence": 0
  })
  const signed_t = wallet.sign(prepared_t)
  console.log(`Prepared ticketed transaction ${signed_t.hash}`)
```

Tip
If you don't plan to submit the TicketCreate transaction right away, you should be sure not to set the `LastLedgerSequence` so that the transaction does not expire. The way you do this varies by library:

- **xrpl.js:** Specify `"LastLedgerSequence": null` when auto-filling the transaction.
- **`rippled`:** Omit `LastLedgerSequence` from the prepared instructions. The server does not provide a value by default.


Prepare Ticketed Tx
div
h4
Select a Ticket:
div
button
Prepare Ticketed Transaction
div
### 9. Submit Ticketed Transaction

Submit the signed transaction blob that you created in the previous step. For example:

JavaScript

```js
  // Submit Ticketed Transaction -----------------------------------------------
  const tx_t = await client.submitAndWait(signed_t.tx_blob)
  console.log(tx_t)
```

Submit Ticketed Tx
Submit

div
### 10. Wait for Validation

Ticketed transactions go through the consensus process the same way that Sequenced transactions do.

table
tbody
tr
th
Transaction ID:
td
(None)
tr
th
Latest Validated Ledger Index:
td
(Not connected)
tr
th
Ledger Index at Time of Submission:
td
(Not submitted)
tr
th
Transaction 
code
LastLedgerSequence
:
td
(Not prepared)
tr
## With Multi-Signing

One of the main use cases for Tickets is to be able to collect signatures for several [multi-signed transactions](/docs/concepts/accounts/multi-signing) in parallel. By using a Ticket, you can send a multi-signed transaction as soon as it is fully signed and ready to go, without worrying about which one will be ready first. 

In this scenario, [step 8, "Prepare Ticketed Transaction"](#8-prepare-ticketed-transaction) is slightly different. Instead of preparing and signing all at once, you would follow the steps for [sending any multi-signed transaction](/docs/tutorials/best-practices/key-management/send-a-multi-signed-transaction): first prepare the transaction, then circulate it among trusted signers to collect their signatures, and finally combine the signatures into the final multi-signed transaction.

You could do this in parallel for several different potential transactions as long as each one uses a different Ticket.

## See Also

- **Concepts:**
  - [Tickets](/docs/concepts/accounts/tickets)
  - [Multi-Signing](/docs/concepts/accounts/multi-signing)
- **Tutorials:**
  - [Set Up Multi-Signing](/docs/tutorials/best-practices/key-management/set-up-multi-signing)
  - [Reliable Transaction Submission](/docs/concepts/transactions/reliable-transaction-submission)
- **References:**
  - [account_objects method](/docs/references/http-websocket-apis/public-api-methods/account-methods/account_objects)
  - [sign_for method](/docs/references/http-websocket-apis/admin-api-methods/signing-methods/sign_for)
  - [submit_multisigned method](/docs/references/http-websocket-apis/public-api-methods/transaction-methods/submit_multisigned)
  - [TicketCreate transaction](/docs/references/protocol/transactions/types/ticketcreate)
  - [Transaction Common Fields](/docs/references/protocol/transactions/common-fields)