# Cross-Consensus Query Language (XCQ)

**URL:** <https://forum.polkadot.network/t/cross-consensus-query-language-xcq/7583>\
**Category:** Tech Talk\
**Created:** [April 26, 2024, 4:39am UTC](https://forum.polkadot.network/t/cross-consensus-query-language-xcq/7583 "2024-04-26T04:39:17Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![indirection42](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.polkadot.network/indirection42/32/4894_2.png) [@indirection42](https://forum.polkadot.network/u/indirection42)\
**Post date:** [October 25, 2024, 2:42am UTC](https://forum.polkadot.network/t/cross-consensus-query-language-xcq/7583/21 "2024-10-25T02:42:26Z")

</div>

We just opened a PR about XCQ RFC. Feedback is welcome!

> <https://github.com/polkadot-fellows/RFCs/pull/126>
>
> Looking for feedback.
> 
> \## Summary
> This proposal introduces XCQ (Cross Consens…us Query), which aims to serve as an intermediary layer between different chain runtime implementations and tools/UIs, to provide a unified interface for cross-chain queries.
> 
> \## Related RFC
> A related XCM-format RFC is drafting.
> 
> \## Related Discussions
> https://forum.polkadot.network/t/wasm-view-functions/1045
> 
> \## PoC implementations
> https://github.com/open-web3-stack/XCQ

---

<div class="post-metadata">

**Author:** ![indirection42](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.polkadot.network/indirection42/32/4894_2.png) [@indirection42](https://forum.polkadot.network/u/indirection42)\
**Post date:** [March 31, 2025, 5:39am UTC](https://forum.polkadot.network/t/cross-consensus-query-language-xcq/7583/22 "2025-03-31T05:39:45Z")

</div>

# PVQ Status Report

## Summary

- Rename project from `XCQ` to `PVQ`
- Refactor PVQ extension system
- Refactor PVQ program macros
- XCM Intergration PoC

## Example Usage

- PVQ Extensions Definitions: [Example](https://github.com/open-web3-stack/PVQ/blob/09da858d7731617a78bbedc1737095e3f5f9e955/pvq-extension-fungibles/src/lib.rs)
- Use `pvq-program` macros to write a guest program. [Example](https://github.com/open-web3-stack/PVQ/blob/09da858d7731617a78bbedc1737095e3f5f9e955/guest-examples/sum-balance-percent/src/main.rs)
- PVQ Extensions Implementation: [Example](https://github.com/open-web3-stack/PVQ/blob/09da858d7731617a78bbedc1737095e3f5f9e955/pvq-test-runner/src/lib.rs)

## Run Examples

Available PoC PVQ examples:

- `guest-sum-balance`: sum the balances of multiple accounts
- `guest-total-supply`: get the total supply of an asset
- `guest-sum-balance-percent`: sum the balances of multiple accounts and calculate the percentage of the total supply

1. Build guest program: `make guests`
2. Run test runner: `cargo run -p pvq-test-runner -- --program output/<guest-program>`  
`guest-examples` contains several guest programs to test the PVQ.

## XCM Integration PoC

The test case of XCM integration is located in [vendor/polkadot-sdk/polkadot/xcm/xcm-simulator/example/src/tests.rs](https://github.com/indirection42/polkadot-sdk/blob/ececb4cbd68d94d1f73b6ab8e5ad8afed1cc9456/polkadot/xcm/xcm-simulator/example/src/tests.rs)

```rust
#[test]
fn test_report_query() {
    ...
}

```

---

<div class="post-metadata">

**Author:** ![indirection42](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.polkadot.network/indirection42/32/4894_2.png) [@indirection42](https://forum.polkadot.network/u/indirection42)\
**Post date:** [July 7, 2025, 1:43pm UTC](https://forum.polkadot.network/t/cross-consensus-query-language-xcq/7583/23 "2025-07-07T13:43:14Z")

</div>

We are happy to share the recent progress of PVQ:

### PVQ Frontend SDK

We have created a [TypeScript SDK](https://github.com/open-web3-stack/pvq-sdk) for interacting with PolkaVM Query(PVQ) enabled chains.  
In summary, the SDK supports the following use cases:

- Create a PVQ program instance by providing the guest program and corresponding metadata files.
- List queryable entrypoints by accessing the metadata.
- Check if the guest program is compatible with the chain’s supported extensions.

For more details, please refer to the [github repo](https://github.com/open-web3-stack/pvq-sdk).

### PVQ Frontend Demo

And we also created a [demo](https://open-web3-stack.github.io/pvq-sdk/) to demonstrate the usage of PVQ-SDK.

In this demo, you can interact with a PoC runtime that implements the `core` and `fungibles` extensions.

1. Clone the [PVQ](https://github.com/open-web3-stack/pvq) repository.
2. Install [bun](https://bun.sh/docs/installation).
3. Run `make tools` to install the required tools.
4. Run `make run` to start the local PoC runtime.
5. Run `make guests` to build the PVQ programs and generate their metadata.
6. Open the [demo](https://open-web3-stack.github.io/pvq-sdk/) in your browser.  
 ![Demo Index](https://europe1.discourse-cdn.com/flex005/uploads/polkadot2/original/2X/0/08dab67b06995a48573cd49705c83ea97afdb2ce.png)
7. Enter the custom endpoint shown in Step 4 and connect to the chain.
8. Upload a PVQ program, such as `guest-sum-balance`, along with the corresponding metadata JSON file, `guest-sum-balance-metadata.json`.  
 ![Upload page](https://europe1.discourse-cdn.com/flex005/uploads/polkadot2/original/2X/0/0bb9f655190b01154be065b6fc65845387af2460.png)
9. Select the program; the program bytecode and metadata should be displayed in the UI.  
 ![Program details](https://europe1.discourse-cdn.com/flex005/uploads/polkadot2/original/2X/9/9c02bb63cada1ae24f4cb38fe4124bbb7d76010f.png)
10. Switch to the `Query` tab, input the query argument, and execute the query to get the result. In the following example, we query the sum of the balances of asset `21` for two accounts: `Alice` and `Bob`.  
 ![Execute query](https://europe1.discourse-cdn.com/flex005/uploads/polkadot2/original/2X/8/8c172a3038f74caf39ad1d68b2f894885c9aa324.png)

### Ongoing Works

We are targeting to the first release of the PVQ as well as demonstrating a more decent Demo to show how PVQ works with different chains.

---

<div class="post-metadata">

**Author:** ![indirection42](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.polkadot.network/indirection42/32/4894_2.png) [@indirection42](https://forum.polkadot.network/u/indirection42)\
**Post date:** [August 4, 2025, 12:23pm UTC](https://forum.polkadot.network/t/cross-consensus-query-language-xcq/7583/24 "2025-08-04T12:23:37Z")

</div>

We’ve built a simple [swap demo](https://open-web3-stack.github.io/pvq-sdk/swap/) showcases how PVQ can facilitate the development of multi-chain Dapps. It has the following core functions:

- List Liquidity Pools: Displays the available token pair pools on the selected chain.

- Get Pool Reserves: Shows the current liquidity reserves for a selected pool.

- Get Swap Price: Show price quote for swapping a specific amount of one token for another.

 ![截屏2025-08-04 20.23.16](https://europe1.discourse-cdn.com/flex005/uploads/polkadot2/original/2X/0/0158b5e11a577caf23bdcb3214af933fb9fb949f.png)

**The main takeaway is that the demo works seamlessly with both Acala and AssetHub, using the exact same front-end logic despite the DEX implementations on these chains being entirely different:**

- Acala: Uses its own custom `module-dex` pallet.

- AssetHub: Uses the `AssetConversion` pallet.

### How It Works

#### Front-end side

From the client’s perspective, the process is simple:

- Check for Extension: The UI first checks if the connected chain (Acala or AssetHub) implements the `swap` extension.

- Construct PVQ program query arguments: If the extension is available, the UI constructs its query with the required arguments (e.g., token pair, amount to swap).

- Call PVQ program Entrypoints: The UI sends the query to the entrypoints of the PVQ program.

The front-end code is completely agnostic of whether it’s talking to Acala’s DEX pallet or AssetHub’s AssetConversion pallet.

#### Runtime side

The heavy lifting is done at the runtime side, which is tailored for each chain. We implement [swap extension](https://github.com/open-web3-stack/PVQ/blob/61950049b9c668f0db4b9fd059f5abb11d3b65e5/pvq-extension-swap) on both Acala and AssetHub, which exposes five extension functions: `quote_price_tokens_for_exact_tokens`, `quote_price_exact_tokens_for_tokens`, `get_liquidity_pool`, `list_pools`, `asset_info`, `assets_info`.

#### PVQ Program

For the corresponding PVQ program, it only has four entrypoints. This is by design and demonstrates one of PVQ’s most powerful features: the ability to perform custom computations in PVQ program.

For example, the `list_pools` entrypoint is actually a composition of extension functions `list_pools` and `assets_info`:

```rust
#[program::entrypoint]
fn entrypoint_list_pools() -> Vec<(AssetInfo, AssetInfo)> {
    let pools = list_pools();
    let mut result = Vec::new();
    let assets_info = assets_info();
    for pool in pools {
        let asset1_info = assets_info.get(&pool.0).cloned();
        let asset2_info = assets_info.get(&pool.1).cloned();
        if let (Some(a1), Some(a2)) = (asset1_info, asset2_info) {
            result.push((a1, a2));
        }
    }
    result
}

```

#### Key Advancement

This demo is a concrete validation of the PVQ vision. We have successfully created a unified, high-level interface for a non-trivial operation (DEX interactions) across two parachains with fundamentally different runtime implementations.

For dApp developers:

- Reduced Complexity: No need to learn the low-level details of every parachain’s pallets.

- Faster Development: Write code once and deploy it across multiple chains.

- Easy Extensibility: As more chains adopt the PVQ swap extension, they will instantly work with existing UIs without requiring any front-end updates.

This advancement is a crucial step toward a more cohesive and developer-friendly Polkadot ecosystem.

#### Next Steps

We are targeting the first release of the PVQ and integrating it into the `polkadot-sdk`.

We welcome feedback, questions, and collaboration from the community. Please feel free to check out the demo and share your thoughts below.

Thank you!

[Previous page](https://forum.polkadot.network/t/cross-consensus-query-language-xcq/7583.md?page=1)
