contract.query.*
Process a named off-chain query of the contract. The query is declare as a function without mut
modifier in the Ink! contract, and the function name will convert to camelCase when calling with SDK.
It share the compatbile API design with @polkadot/api-contract
.
Usage
import * as fs from 'node:fs'
import { client, pair, cert } from './setup'
const abi = fs.readFileSync('path/to/your/Certificate.abi.json', 'utf-8')
const contract = await getContract({
client,
contractId: '0x...',
abi,
})
const result = await contract.query.getCaller(pair.address, { cert }, 'Hi Remark')
const callerAddress = result.output.asOk
Parameters
address
string | AccountId
The address of the wallet that singing the certificateData
for the query.
options
PinkContractQueryOptions
The options for the query. It's a object with the following properties:
cert
:certificateData
. Required. ThecertificateData
must signed by theaddress
.salt
:string
. Optional. The salt for the query signing.estimating
:boolean
. Optional. 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
:number | bigint | BN
. Optional. Use ifestimating
istrue
, it means the estimating will assume the user will deposit thedeposit
amount of PHA at the same time.transfer
:number | bigint | BN
. Optional. Use ifestimating
istrue
, it means the estimating will assume the user will transfer thetransfer
amount to cluster at the same time.
...rest
any[]
...rest
is the arguments for the query.
Returns
ContractCallResult<'promise', PinkContractCallOutcome<ILooseResult<TResult=Codec, TErr=Codec>>>
The result of the query is the ContractCallResult
instance, same behavior to the @Polkadot/api-contract
.
If the query returns meaningful result, you need fetch it from the output
property, then use isOk
to check and use asOk
to get the succeed result.
const callerAddress = result.output.asOk