Skip to main content

query

Allows you to submit scripts to query the blockchain.

Import

You can import the entire package and access the function:


_10
import * as fcl from "@onflow/fcl"
_10
_10
fcl.query(opts)

Or import directly the specific function:


_10
import { query } from "@onflow/fcl"
_10
_10
query(opts)

Usage


_16
import * as fcl from '@onflow/fcl';
_16
_16
const result = await fcl.query({
_16
cadence: `
_16
access(all) fun main(a: Int, b: Int, addr: Address): Int {
_16
log(addr)
_16
return a + b
_16
}
_16
`,
_16
args: (arg, t) => [
_16
arg(7, t.Int), // a: Int
_16
arg(6, t.Int), // b: Int
_16
arg('0xba1132bc08f82fe2', t.Address), // addr: Address
_16
],
_16
});
_16
console.log(result); // 13

Parameters

opts (optional)

  • Type:

_10
export interface QueryOptions {
_10
cadence?: string
_10
args?: ArgsFn
_10
template?: any
_10
isSealed?: boolean
_10
limit?: number
_10
}

  • Description: Query options configuration

Returns

Promise<any>

A JSON representation of the response


Rate this page