Skip to main content

Vouchers

Vouchers represent transactions that can be carried out on the base layer blockchain, such as asset transfers. They are used to effect changes in the base layer based on the application's state.

1. Get Voucher by Index

Retrieve a specific voucher based on its index and associated input index.

query voucher($voucherIndex: Int!, $inputIndex: Int!) {
voucher(voucherIndex: $voucherIndex, inputIndex: $inputIndex) {
index
input {
index
timestamp
msgSender
blockNumber
}
destination
payload
proof {
validity {
inputIndexWithinEpoch
outputIndexWithinInput
outputHashesRootHash
vouchersEpochRootHash
noticesEpochRootHash
machineStateHash
outputHashInOutputHashesSiblings
outputHashesInEpochSiblings
}
context
}
}
}

For vouchers, the API provides access to proof data that can be used for validation on the base layer blockchain. This proof data is accessible through the Proof field on voucher objects.

Arguments

NameTypeDescription
voucherIndexInt!The index of the voucher to retrieve.
inputIndexInt!The index of the associated input.

Response Type

Voucher

2. Get Vouchers

Retrieve a list of vouchers with support for pagination.

query vouchers($first: Int, $after: String) {
vouchers(first: $first, after: $after) {
edges {
node {
index
input {
index
timestamp
msgSender
blockNumber
}
destination
payload
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}

Arguments

NameTypeDescription
firstIntNumber of vouchers to retrieve (for pagination).
afterStringCursor to start retrieving vouchers from (for pagination).

Response Type

VoucherConnection

3. Get Vouchers by Input

Retrieve vouchers associated with a specific input.

query vouchersByInput($inputIndex: Int!, $first: Int, $after: String) {
input(index: $inputIndex) {
vouchers(first: $first, after: $after) {
edges {
node {
index
destination
payload
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}
}

Arguments

NameTypeDescription
inputIndexInt!Index of the input to retrieve vouchers for.
firstIntNumber of vouchers to retrieve (for pagination).
afterStringCursor to start retrieving vouchers from (for pagination).

Response Type

VoucherConnection

Examples

  1. Fetching a specific voucher:

      query {
    voucher(voucherIndex: 3, inputIndex: 2) {
    index
    destination
    payload
    proof {
    validity {
    inputIndexWithinEpoch
    outputIndexWithinInput
    }
    context
    }
    }
    }
  2. Listing earlier(first 5) vouchers:

    query {
    vouchers(first: 5) {
    edges {
    node {
    index
    input {
    index
    timestamp
    }
    destination
    payload
    }
    cursor
    }
    pageInfo {
    hasNextPage
    endCursor
    }
    }
    }
  3. Retrieving vouchers associated with a specific input:

    query {
    input(index: 10) {
    vouchers(first: 3) {
    edges {
    node {
    index
    destination
    payload
    }
    cursor
    }
    pageInfo {
    hasNextPage
    endCursor
    }
    }
    }
    }

© 2024 Cartesi Foundation Ltd. All rights reserved.

The Cartesi Project is commissioned by the Cartesi Foundation.

We use cookies to ensure that we give you the best experience on our website. By using the website, you agree to the use of cookies.