contract.q.*
Send a query to off-chain node and getting the result immediately.
Usage
import * as fs from 'node:fs'
import { getContract, AccountId } from '@phala/sdk'
import { client, provider } from './setup'
const abi = fs.readFileSync('path/to/abi.json', 'utf-8')
const contract = await getContract({
client,
contractId: '0x...',
abi,
provider, // This is required
})
const callerAddress = await contract.q.getCaller<AccountId>({
args: ['Hi Remark']
})
You should take care of the parameters and the returns, it's totally different from contract.query.*
.
const callerAddress = await contract.q.getCaller({
args: ['Hi Remark']
})
const result = await contract.query.getCaller(pair.address, { cert }, 'Hi Remark')
callerAddress === result.output
Parameters
args
any[]
The arguments for the query.
origin
(optional)
string | AccountId
The address of the wallet that singing the certificateData
for the query.
cert
(optional)
certificateData
The certificateData
must signed by the address
.
salt
(optional)
string
The salt for the query signing.
estimating
(optional)
boolean
Declare it's estimating or not. If true, it will simulate the query and return the estimate result for gas fee and storage deposit fee.
deposit
(optional)
number | bigint | BN
Use if estimating
is true
, it means the estimating will assume the user will deposit the deposit
amount of PHA at the same time.
transfer
(optional)
number | bigint | BN
Use if estimating
is true
, it means the estimating will assume the user will transfer the transfer
amount to cluster at the same time.
Returns
Promise<T=Codec>
The output of the query. You can use type hinting for the result type:
const callerAddress = await contract.q.getCaller<AccountId>({
args: ['Hi Remark']
})