# How blockchain state and transactions work · Your first Rell app on Chromia · Learn Chromia

> This lesson looks at how Chromia stores transactions and manages state. Start with the diagram from Lesson 1, which traced a create_book transaction through…

Source: https://chromia.com/learn/book-review/blockchain-transactions/query-transaction/

Your first Rell app on ChromiaLesson 19 of 26

1. [01Your first Rell app on Chromia](https://chromia.com/learn/book-review/introduction/)
2. [02Set up your project](https://chromia.com/learn/book-review/setup/)
3. [03Rell project structure](https://chromia.com/learn/book-review/rell-structure/)

Part 1: Define your first entity

1. [04Overview](https://chromia.com/learn/book-review/book-entity/)
2. [05Create your first entity](https://chromia.com/learn/book-review/book-entity/tables/)
3. [06Add your first operation](https://chromia.com/learn/book-review/book-entity/basic-operations/)
4. [07Query every book](https://chromia.com/learn/book-review/book-entity/write-queries/)

Part 2: Add a related entity

1. [08Overview](https://chromia.com/learn/book-review/book-review-entity/)
2. [09Define the book review entity](https://chromia.com/learn/book-review/book-review-entity/tables/)
3. [10Add an operation for creating book reviews](https://chromia.com/learn/book-review/book-review-entity/basic-operations/)
4. [11Query all reviews for a book](https://chromia.com/learn/book-review/book-review-entity/write-queries/)

Part 3: Checking and validating inputs

1. [12Overview](https://chromia.com/learn/book-review/input-verification/)
2. [13Verify inputs](https://chromia.com/learn/book-review/input-verification/input-verification/)
3. [14Return structured results from queries](https://chromia.com/learn/book-review/input-verification/structure/)

Part 4: Signing transactions and filtering queries

1. [15Overview](https://chromia.com/learn/book-review/sign-transaction/)
2. [16Sign a transaction](https://chromia.com/learn/book-review/sign-transaction/sign-transaction/)
3. [17Filter and sort query results](https://chromia.com/learn/book-review/sign-transaction/structure/)

Part 5: Blockchain state and transactions explained

1. [18Overview](https://chromia.com/learn/book-review/blockchain-transactions/)
2. [19How blockchain state and transactions work](https://chromia.com/learn/book-review/blockchain-transactions/query-transaction/)
3. [20Walking through an example](https://chromia.com/learn/book-review/blockchain-transactions/example/)

Part 6: Create the client

1. [21Overview](https://chromia.com/learn/book-review/build-client/)
2. [22Prerequisites](https://chromia.com/learn/book-review/build-client/prerequisites/)
3. [23Establishing a connection to Chromia](https://chromia.com/learn/book-review/build-client/sign-transaction/)
4. [24Query the blockchain using postchain-client](https://chromia.com/learn/book-review/build-client/query-blockchain/)
5. [25Complete the example](https://chromia.com/learn/book-review/build-client/complete-example/)

1. [26What’s next?](https://chromia.com/learn/book-review/what-next/)

[Learn](https://chromia.com/learn/)[Your first Rell app on Chromia](https://chromia.com/learn/book-review/)

19 / 26Part 5: Blockchain state and transactions explainedBeginner

# How blockchain state and transactions work

This lesson looks at how Chromia stores transactions and manages state. Start with the diagram from Lesson 1, which traced a `create_book` transaction through the system:

* You sign the transaction `create_book("ISBN1234", "1984", "George Orwell")`.
* The Chromia Node receives the transaction, validates it, and passes it on to the blockchain.
* The operation runs `create_book(isbn = isbn, title = title, author = author);`, and Rell applies the change to the DApp table state.
* Once confirmed, the transaction goes into a block on the blockchain, and the DApp table state reflects the update.

The diagram shows two things: the transaction is recorded on the blockchain, and the operation inside it changes the state. The rest of this lesson examines that split so you can see how the blockchain and the state differ.

First, you fetch the state with the `get_all_books` query.

## Querying state for all books

A query such as `get_all_books` reads only from the DApp table state. You want the current set of books, so the state is the right place to look. The query follows this path:

Step by step:

* You send a request for all books to the Chromia Node.
* The node hands the query to Rell.
* Rell runs a query against the state to retrieve every book.
* The state executes it and sends the result back to Rell.
* Rell returns the full list of books from the state to you.

Next, you query the blockchain itself for transactions.

## Querying the blockchain for transactions

Here you query the blockchain to retrieve every transaction that produced the current DApp table state.

The blockchain keeps each transaction in the system `transaction` entity. One of its fields, `tx_data`, holds the complete transaction as GTV-encoded binary: operations, arguments, signers, and signatures.

Rell's built-in `gtx_transaction` type lets you decode that binary and work with its contents.

### Adding a Query

Put this query in `src/main/queries.rell`:

src/main/queries.rell

```
query get_transactions() {
  return transaction @* { } ( gtx_transaction.from_bytes(.tx_data) );
}
```

The query returns a list of structured transactions. Each one contains:

* The RID of the blockchain that holds the transaction
* Every operation along with its arguments
* The transaction's signers
* The matching signatures

For a full description of the decoded transaction format, see the [system entities reference](https://docs.chromia.com/rell/language-features/systemlib/system-entities).

That completes the transaction query definitions. The next lesson shows you how to run these queries in practice.

Written for this site from Chromia’s public course. Code samples are the course’s own.

[← Previous**Part 5: Blockchain state and transactions explained**](https://chromia.com/learn/book-review/blockchain-transactions/)[Next →**Walking through an example**](https://chromia.com/learn/book-review/blockchain-transactions/example/)

On this page

* [Querying state for all books](#querying-state-for-all-books)
* [Querying the blockchain for transactions](#querying-the-blockchain-for-transactions)
