OCAP Client 通过 GraphQL 与区块链进行交互。其方法主要分为两类:
- 查询 (Queries):这些是只读操作,用于从区块链中获取数据,例如检索账户状态、列出交易或获取常规链信息。它们不会改变链的状态。
- 变更 (Mutations):这些是写入操作,会修改区块链的状态。发送交易是变更操作的主要示例。
本节提供了该客户端所有可用的查询和变更方法的完整参考。
查询方法
查询用于从区块链中检索数据。以下是所有可用查询方法的完整列表。
getAccountState
检索特定账户的当前状态,包括其余额、nonce 和其他详细信息。
参数
- address
string(required) — 要查询的账户地址。 - height
string— 查询特定区块高度下的状态。 - keys
string[]— 要检索的特定字段。 - traceMigration
boolean— 如果为 true,则追踪账户的迁移历史。
返回
- ResponseGetAccountState
object— 包含响应码和账户状态的对象。- code
string— 响应的状态码(例如 'OK')。 - state
AccountState— 账户的详细状态。
- code
getAssetState
检索特定资产 (NFT) 的当前状态。
参数
- address
string(required) — 要查询的资产地址。 - height
string— 查询特定区块高度下的状态。 - keys
string[]— 要检索的特定字段。
返回
- ResponseGetAssetState
object— 包含响应码和资产状态的对象。- code
string— 响应的状态码。 - state
AssetState— 资产的详细状态。
- code
getFactoryState
获取特定资产工厂的状态。
参数
- address
string(required) — 要查询的工厂地址。
返回
- ResponseGetFactoryState
object— 包含响应码和工厂状态的对象。- code
string— 响应的状态码。 - state
AssetFactoryState— 资产工厂的详细状态。
- code
getDelegateState
检索委托关系的状态。
参数
- address
string(required) — 要查询的委托地址。 - height
string— 查询特定区块高度下的状态。 - keys
string[]— 要检索的特定字段。
返回
- ResponseGetDelegateState
object— 包含响应码和委托状态的对象。- code
string— 响应的状态码。 - state
DelegateState— 委托的详细状态。
- code
getTokenState
获取特定同质化通证的状态。
参数
- address
string(required) — 要查询的通证地址。
返回
- ResponseGetTokenState
object— 包含响应码和通证状态的对象。- code
string— 响应的状态码。 - state
TokenState— 通证的详细状态。
- code
getEvidenceState
通过哈希值检索证据记录。
参数
- hash
string(required) — 要检索的证据的哈希值。
返回
- ResponseGetEvidenceState
object— 包含响应码和证据状态的对象。- code
string— 响应的状态码。 - state
EvidenceState— 证据的详细状态。
- code
getForgeState
获取 OCAP 区块链的整体配置和状态。
参数
- height
string— 查询特定区块高度下的状态。 - keys
string[]— 要检索的特定字段。
返回
- ResponseGetForgeState
object— 包含响应码和链状态的对象。- code
string— 响应的状态码。 - state
ForgeState— OCAP 链的详细状态。
- code
getTokenFactoryState
检索特定通证工厂的状态。
参数
- address
string(required) — 要查询的通证工厂地址。
返回
- ResponseGetTokenFactoryState
object— 包含响应码和通证工厂状态的对象。- code
string— 响应的状态码。 - state
TokenFactoryState— 通证工厂的详细状态。
- code
getTx
通过哈希值获取单笔交易。
参数
- hash
string(required) — 要检索的交易的哈希值。
返回
- ResponseGetTx
object— 包含响应码和交易详情的对象。- code
string— 响应的状态码。 - info
TransactionInfo— 交易的详细信息。
- code
getBlock
通过区块高度检索单个区块。
参数
- height
string(required) — 要检索的区块的高度。
返回
- ResponseGetBlock
object— 包含响应码和区块详情的对象。- code
string— 响应的状态码。 - block
BlockInfo— 区块的详细信息。
- code
getBlocks
检索区块列表,可附带筛选条件。
参数
- paging
PageInput— 分页设置。 - heightFilter
RangeFilterInput— 按高度范围筛选区块。 - emptyExcluded
boolean— 如果为 true,则排除没有交易的区块。
返回
- ResponseGetBlocks
object— 包含分页信息和区块列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - blocks
BlockInfoSimple[]— 简化区块对象的数组。
- code
getUnconfirmedTxs
获取在内存池中但尚未确认的交易。
参数
- paging
PageInput— 分页设置。
返回
- ResponseGetUnconfirmedTxs
object— 包含分页信息和未确认交易列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - unconfirmedTxs
UnconfirmedTxs— 未确认交易的详细信息。
- code
getChainInfo
检索关于区块链的常规信息。
参数
此方法没有任何参数。
返回
- ResponseGetChainInfo
object— 包含响应码和链信息的对象。- code
string— 响应的状态码。 - info
ChainInfo— 链的详细信息。
- code
getConfig
获取节点的配置。
参数
- parsed
boolean— 如果为 true,则返回解析后的配置。
返回
- ResponseGetConfig
object— 包含响应码和配置的对象。- code
string— 响应的状态码。 - config
string— 节点的配置,以字符串形式表示。
- code
getNetInfo
检索网络信息,包括已连接的对等节点。
参数
此方法没有任何参数。
返回
- ResponseGetNetInfo
object— 包含响应码和网络信息的对象。- code
string— 响应的状态码。 - netInfo
NetInfo— 详细的网络信息。
- code
getNodeInfo
检索有关被查询的特定节点的信息。
参数
此方法没有任何参数。
返回
- ResponseGetNodeInfo
object— 包含响应码和节点信息的对象。- code
string— 响应的状态码。 - info
NodeInfo— 有关节点的详细信息。
- code
getValidatorsInfo
获取有关当前验证者集的信息。
参数
此方法没有任何参数。
返回
- ResponseGetValidatorsInfo
object— 包含响应码和验证者信息的对象。- code
string— 响应的状态码。 - validatorsInfo
ValidatorsInfo— 有关验证者的详细信息。
- code
getForgeStats
检索有关区块链活动的各种统计数据。
参数
此方法没有任何参数。
返回
- ResponseGetForgeStats
object— 包含响应码和链统计数据的对象。- code
string— 响应的状态码。 - forgeStats
ForgeStats— 有关 OCAP 链的各种统计数据。
- code
listAssetTransactions
列出与特定资产相关的所有交易。
参数
- address
string(required) — 资产的地址。 - paging
PageInput— 分页设置。
返回
- ResponseListAssetTransactions
object— 包含分页信息和交易列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - transactions
IndexedTransaction[]— 交易对象的数组。
- code
listAssets
列出所有资产,可通过所有者或工厂进行筛选。
参数
- paging
PageInput— 分页设置。 - ownerAddress
string— 按所有者地址筛选资产。 - factoryAddress
string— 按工厂地址筛选资产。 - timeFilter
TimeFilterInput— 按时间范围筛选资产。
返回
- ResponseListAssets
object— 包含分页信息和资产列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - assets
IndexedAssetState[]— 资产状态对象的数组。
- code
listBlocks
列出区块,并提供多种筛选选项。
参数
- paging
PageInput— 分页设置。 - proposer
string— 按提议者地址筛选区块。 - timeFilter
TimeFilterInput— 按时间范围筛选区块。 - heightFilter
RangeFilterInput— 按高度范围筛选区块。 - numTxsFilter
RangeFilterInput— 按交易数量筛选区块。 - numInvalidTxsFilter
RangeFilterInput— 按无效交易数量筛选区块。
返回
- ResponseListBlocks
object— 包含分页信息和区块列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - blocks
IndexedBlock[]— 区块对象的数组。
- code
listTopAccounts
列出持有特定通证余额最高的账户。
参数
- paging
PageInput— 分页设置。 - tokenAddress
string— 通证的地址。如果未提供,则默认为原生通证。 - timeFilter
TimeFilterInput— 按时间范围筛选账户。
返回
- ResponseListTopAccounts
object— 包含分页信息和排名靠前账户列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - accounts
IndexedAccountState[]— 账户状态对象的数组。
- code
listTransactions
一个功能强大的方法,可通过多种筛选条件列出交易。
参数
- paging
PageInput— 分页设置。 - timeFilter
TimeFilterInput— 按时间范围筛选交易。 - addressFilter
AddressFilterInput— 按发送方或接收方地址筛选交易。 - typeFilter
TypeFilterInput— 按交易类型筛选。 - validityFilter
ValidityFilterInput— 按交易有效性筛选。 - factoryFilter
FactoryFilterInput— 按工厂地址筛选。 - tokenFilter
TokenFilterInput— 按通证地址筛选。 - assetFilter
AssetFilterInput— 按资产地址筛选。 - accountFilter
AccountFilterInput— 按账户地址筛选。 - txFilter
TxFilterInput— 按交易哈希筛选。 - rollupFilter
RollupFilterInput— 按 Rollup 地址筛选。 - stakeFilter
StakeFilterInput— 按质押地址筛选。 - delegationFilter
DelegationFilterInput— 按委托地址筛选。 - tokenFactoryFilter
TokenFactoryFilterInput— 按通证工厂地址筛选。
返回
- ResponseListTransactions
object— 包含分页信息和交易列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - transactions
IndexedTransaction[]— 交易对象的数组。
- code
listTokens
列出链上所有的同质化通证。
参数
- paging
PageInput— 分页设置。 - issuerAddress
string— 按发行方地址筛选通证。 - timeFilter
TimeFilterInput— 按时间范围筛选通证。
返回
- ResponseListTokens
object— 包含分页信息和通证列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - tokens
IndexedTokenState[]— 通证状态对象的数组。
- code
listFactories
列出链上所有的资产工厂。
参数
- paging
PageInput— 分页设置。 - ownerAddress
string— 按所有者地址筛选工厂。 - addressList
string[]— 要查询的工厂地址列表。 - timeFilter
TimeFilterInput— 按时间范围筛选工厂。
返回
- ResponseListFactories
object— 包含分页信息和工厂列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - factories
IndexedFactoryState[]— 工厂状态对象的数组。
- code
getAccountTokens
检索特定账户的通证余额。
参数
- address
string(required) — 账户的地址。 - token
string— 要查询的特定通证地址。
返回
- ResponseGetAccountTokens
object— 包含响应码和账户通证列表的对象。- code
string— 响应的状态码。 - tokens
AccountToken[]— 通证余额对象的数组。
- code
getStakeState
获取特定质押的状态。
参数
- address
string(required) — 要查询的质押地址。 - height
string— 查询特定区块高度下的状态。 - keys
string[]— 要检索的特定字段。
返回
- ResponseGetStakeState
object— 包含响应码和质押状态的对象。- code
string— 响应的状态码。 - state
StakeState— 质押的详细状态。
- code
listStakes
列出所有质押记录,可附带筛选条件。
参数
- paging
PageInput— 分页设置。 - addressFilter
AddressFilterInput— 按发送方或接收方地址筛选质押。 - timeFilter
TimeFilterInput— 按时间范围筛选质押。 - assetFilter
AssetFilterInput— 按资产地址筛选质押。
返回
- ResponseListStakes
object— 包含分页信息和质押列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - stakes
IndexedStakeState[]— 质押状态对象的数组。
- code
getRollupState
检索特定 Rollup 的状态。
参数
- address
string(required) — 要查询的 Rollup 地址。 - height
string— 查询特定区块高度下的状态。 - keys
string[]— 要检索的特定字段。
返回
- ResponseGetRollupState
object— 包含响应码和 Rollup 状态的对象。- code
string— 响应的状态码。 - state
RollupState— Rollup 的详细状态。
- code
listRollups
列出链上所有的 Rollup。
参数
- paging
PageInput— 分页设置。 - tokenAddress
string— 按通证地址筛选 Rollup。 - foreignTokenAddress
string— 按外部通证地址筛选 Rollup。 - timeFilter
TimeFilterInput— 按时间范围筛选 Rollup。
返回
- ResponseListRollups
object— 包含分页信息和 Rollup 列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - rollups
IndexedRollupState[]— Rollup 状态对象的数组。
- code
getRollupBlock
从 Rollup 侧链获取特定区块。
参数
- hash
string— Rollup 区块的哈希值。 - height
string— Rollup 区块的高度。 - rollupAddress
string(required) — Rollup 的地址。
返回
- ResponseGetRollupBlock
object— 包含响应码和 Rollup 区块的对象。- code
string— 响应的状态码。 - block
RollupBlock— Rollup 区块的详细信息。
- code
listRollupBlocks
列出 Rollup 侧链的区块。
参数
- paging
PageInput— 分页设置。 - rollupAddress
string(required) — Rollup 的地址。 - tokenAddress
string— 按通证地址筛选。 - proposer
string— 按提议者地址筛选。 - validatorFilter
ValidatorFilterInput— 按验证者筛选。 - txFilter
TxFilterInput— 按交易哈希筛选。 - timeFilter
TimeFilterInput— 按时间范围筛选。
返回
- ResponseListRollupBlocks
object— 包含分页信息和 Rollup 区块列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - blocks
IndexedRollupBlock[]— Rollup 区块对象的数组。
- code
listRollupValidators
列出特定 Rollup 的验证者。
参数
- paging
PageInput— 分页设置。 - rollupAddress
string(required) — Rollup 的地址。
返回
- ResponseListRollupValidators
object— 包含分页信息和 Rollup 验证者列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - validators
IndexedRollupValidator[]— Rollup 验证者对象的数组。
- code
listDelegations
列出所有委托记录。
参数
- paging
PageInput— 分页设置。 - from
string— 按委托人地址筛选。 - to
string— 按受托人地址筛选。 - timeFilter
TimeFilterInput— 按时间范围筛选。
返回
- ResponseListDelegations
object— 包含分页信息和委托列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - delegations
IndexedDelegationState[]— 委托状态对象的数组。
- code
search
对账户、资产或交易进行关键字搜索。
参数
- paging
PageInput— 分页设置。 - keyword
string(required) — 要搜索的关键字。
返回
- ResponseSearch
object— 包含分页信息和搜索结果的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - results
SearchResult[]— 搜索结果对象的数组。
- code
estimateGas
估算交易所需的 gas。
参数
- typeUrl
string(required) — 交易的类型 URL。 - tx
string(required) — 已编码的交易字符串。
返回
- ResponseEstimateGas
object— 包含响应码和 gas 估算值的对象。- code
string— 响应的状态码。 - estimate
GasEstimate— 估算的 gas。
- code
listTokenFlows
追踪账户之间的通证流动。
参数
- paging
PageInput— 分页设置。 - accountAddress
string(required) — 要追踪的账户地址。 - tokenAddress
string— 要追踪的通证地址。 - depth
number— 追踪的深度。 - direction
TokenFlowDirection— 流动方向(IN 或 OUT)。
返回
- ResponseListTokenFlows
object— 包含分页信息和通证流动数据的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - data
IndexedTokenFlow[]— 通证流动对象的数组。
- code
verifyAccountRisk
评估给定账户的风险状况。
参数
- accountAddress
string(required) — 要验证的账户地址。 - tokenAddress
string— 用于提供上下文的通证地址。
返回
- ResponseVerifyAccountRisk
object— 包含响应码和风险验证结果的对象。- code
string— 响应的状态码。 - data
VerifyAccountRiskResult— 风险验证的结果。
- code
getTokenDistribution
检索给定通证的分布统计数据。
参数
- tokenAddress
string(required) — 通证的地址。
返回
- ResponseGetTokenDistribution
object— 包含响应码和通证分布数据的对象。- code
string— 响应的状态码。 - data
TokenDistribution— 通证分布统计数据。
- code
listTokenFactories
列出链上所有的通证工厂。
参数
- paging
PageInput— 分页设置。 - tokenAddress
string— 按通证地址筛选。 - reserveAddress
string— 按储备通证地址筛选。 - owner
string— 按所有者地址筛选。 - timeFilter
TimeFilterInput— 按时间范围筛选。
返回
- ResponseListTokenFactories
object— 包含分页信息和通证工厂列表的对象。- code
string— 响应的状态码。 - page
PageInfo— 分页信息。 - tokenFactories
IndexedTokenFactoryState[]— 通证工厂状态对象的数组。
- code
变更方法
变更用于发送修改区块链状态的交易。
sendTx
将预先签名的交易广播到网络。这是所有写入操作的基础方法。关于创建和签署交易,请参阅 高级 API 和 交易生命周期 指南。
参数
- tx
string(required) — 已编码的交易字符串。 - wallet
object(required) — 用于签名的钱包对象。 - token
string— 身份验证令牌(如果需要)。 - commit
boolean(default:true) — 如果为 true,则等待交易提交到区块中。 - extra
string— 要包含的额外数据。
返回
- ResponseSendTx
object— 包含响应码和交易哈希的对象。- code
string— 响应的状态码。 - hash
string— 已提交交易的哈希。
- code
示例
// 本示例假设 `signedTx` 是一个经过正确编码和签名的交易字符串。
// 关于如何创建它,请参阅其他指南。
const signedTx = '...';
const wallet = { ... }; // 签署该交易的钱包
try {
const { hash } = await client.sendTx({ tx: signedTx, wallet });
console.log('Transaction sent successfully! Hash:', hash);
} catch (error) {
console.error('Failed to send transaction:', error);
}