Cheqd 的脚本 SDK 类型
i️ 概览
其目的 @cheqd/sdk 国家防范机制一揽子计划 提供与cheqd网络互动的基础功能。 它结合了 分散标识符( DID) 财务报告和审定财务报表 已链接资源 模块,将其放入使用 Cosmos 交易包 科斯姆杰斯。 。 。 .
此套件被其他 SDKs/ librarys 所消耗, 例如 : Cheqd 的维拉莫 SDK 财务报告和审定财务报表 克里多语 添加 cheqd 网络支持.
该套件包括:
- TypeScript Protobuf 定义 用于自定义 cheqd Cosmos SDK 模块
- 科斯姆杰斯,用于基础 Cosmos SDK 模块功能
* 特性
我们的身份证件网站提供 用于使用身份特性的教程 在契克德网络.
通过这个SDK,开发者能够:
* 工具
- ✅ 原始有效载荷创建者: 使用户能够根据使用情况,生成一个有效的原始的DD有效载荷。 譬如说,
did-provider-cheqd在 CLI 应用程序中调用此帮助 . - ✅ 身份密钥转换器: 使用户能够从不同种类的SDK转换出特定的密钥格式,方法是将输入密钥转换为一个cheqd特定DD交易(例如.
createDidDocTx, (中文(简体) ),updateDidDocTx) (中文(简体) ). 例如,Cheqd的Veramo SDK使用这个帮助器,使用户能够用Veramo SDK特定格式将一个密钥传递到cheqd标志输入密钥接口.
• 收费摘要
Cheqd SDK提供了全面的收费抽象功能,允许用户使用来自其他链条的IBC符来支付交易费,而不是本地的CHEQ符. 这个功能通过允许用户在不持有原生代号的情况下进行切换来实现跨链互操作并改进用户体验.
概览
Cheqd上的收费抽象化使:
- 跨链收费: 使用其他Cosmos连锁公司的代号支付交易费
- 东道区管理: 添加和配置支持的链条以进行收费抽象
- 自动令牌互换: 将中型散货箱代币转换为CHEQ, 用于幕后付费
- 模块账户供资: 为收费抽取业务提供流动性
QQ 模块文件
付费抽象功能在以下文件中实现:
CJS (CommonJS) (中文(简体) )数字 :
- 主要模块:
cjs/src/modules/feeabstraction.ts - 类型定义 :
cjs/src/types.ts
无害环境管理(ECMAScript模块)数字 :
- 主要模块:
esm/src/modules/feeabstraction.ts - 类型定义 :
esm/src/types.ts
基本用途
设置收费摘要
import { createCheqdSDK, CheqdNetwork } from '@cheqd/sdk';
// Create wallet instance (e.g., using DirectSecp256k1HdWallet from CosmJS)
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
const wallet = await DirectSecp256k1HdWallet.fromMnemonic('your mnemonic here', { prefix: 'cheqd' }); // replace with your mnemonic, remember to keep it secure
// Set up the SDK options with fee abstraction capabilities
const sdkOptions = {
modules: [
FeeabstractionModule as unknown as AbstractCheqdSDKModule,
// other modules can be added here
],
// other SDK options can be configured here
rpcUrl: 'https://rpc.cheqd.network', // or your preferred RPC endpoint
network: CheqdNetwork.Testnet, // or CheqdNetwork.Mainnet
wallet,
};
// Initialize SDK with fee abstraction support
const sdk = await createCheqdSDK(sdkOptions);
中型散货箱资产要求
在使用收费抽象功能之前, 请确保您的账户拥有从 Osmosis 等支持的链条连接起来的必要 中型散货箱资产 :
骨质疏导资产
要使用收费抽象,你需要在你的Cheqd账户中存有从Osmosis中取出的国际散货箱代币:
// Example IBC denominations that might be supported
const supportedIBCDenoms = [
'ibc/1480B8FD20AD5FCAE81EA87584D269547DD4D436843C1D20F15E00EB64743EF4', // ATOM from Osmosis
'ibc/14F9BC3E44B8A9C1BE1FB08980FAB87034C9905EF17CF2442BE1FA40E2E5F16', // OSMO from Osmosis
// Add other supported IBC denominations
];
// Your account should have these IBC tokens available
async function checkIBCBalances(accountAddress: string) {
const balances = await sdk.querier.bank.allBalances({ address: accountAddress });
const ibcBalances = balances.balances.filter(balance =>
balance.denom.startsWith('ibc/')
);
console.log('Available IBC tokens:', ibcBalances);
return ibcBalances;
}
说明:为了将资产从奥斯默斯通到契克德,可以使用:
- 前端 Osmosis 缩写 人工转移
- IBC 传输工具 跨链转让
- 通过 CLI 直接的 IBC 传输命令
QQ 查询收费摘要数据
主机链配置
async function queryHostChainConfig() {
const configResponse = await sdk.querier[defaultFeeabstractionExtensionKey].hostChainConfig({
// Query parameters can be added here if needed
});
console.log('Host chain configuration:', configResponse);
}
模块余额
async function queryModuleBalances() {
const balancesResponse = await sdk.querier[defaultFeeabstractionExtensionKey].feeabsModuleBalances({
// Query parameters can be added here if needed
});
console.log('Fee abstraction module balances:', balancesResponse);
}
奥斯默斯TWAP数据
async function queryOsmosisTWAP() {
const twapResponse = await sdk.querier[defaultFeeabstractionExtensionKey].osmosisArithmeticTwap({
poolId: '1', // Pool ID on Osmosis
baseAsset: 'uosmo',
quoteAsset: 'ibc/ABC123...',
startTime: new Date(Date.now() - 24 * 60 * 60 * 1000), // 24 hours ago
endTime: new Date()
});
console.log('TWAP data:', twapResponse);
}
治理业务
收费抽象支持配置变化的治理建议:
添加主机区
import { MsgAddHostZone } from '@cheqd/ts-proto/feeabstraction/feeabs/v1beta1/index';
async function proposeAddHostZone() {
const hostZoneData: MsgAddHostZone = {
authority: 'cheqd1gov...', // Governance authority address
hostChainId: 'osmosis-1',
connectionId: 'connection-0',
ibcDenom: 'ibc/ABC123...',
nativeDenom: 'uosmo',
transferChannelId: 'channel-0',
minSwapAmount: '1000'
};
const proposalResponse = await sdk.addHostZoneProposal(
hostZoneData,
'Add Osmosis as Host Zone', // Proposal title
[{ denom: 'ncheq', amount: '10000000000' }], // Deposit
'cheqd1proposer...', // Proposer address
{
amount: [{ denom: 'ncheq', amount: '5000' }],
gas: '300000'
}
);
console.log('Host zone proposal submitted:', proposalResponse.transactionHash);
}
更新主机区配置
async function proposeUpdateHostZone() {
const updateData = {
authority: 'cheqd1gov...',
hostChainId: 'osmosis-1',
// Updated configuration parameters
minSwapAmount: '2000' // New minimum swap amount
};
const updateResponse = await sdk.updateHostZoneProposal(
updateData,
'Update Osmosis Host Zone Configuration',
[{ denom: 'ncheq', amount: '10000000000' }],
'cheqd1proposer...',
{
amount: [{ denom: 'ncheq', amount: '5000' }],
gas: '300000'
}
);
console.log('Update proposal submitted:', updateResponse.transactionHash);
}
高级配置
TWAP 价格数据查询
async function sendTWAPQuery() {
const twapQueryResponse = await sdk.sendQueryIbcDenomTWAP(
'cheqd1sender...',
'ibc/ABC123...', // IBC denomination
{
amount: [{ denom: 'ncheq', amount: '5000' }],
gas: '200000'
},
'Query TWAP for price data'
);
console.log('TWAP query sent:', twapQueryResponse);
}
完整收费摘要工作流程
async function completeFeeAbstractionWorkflow() {
try {
// 1. Check account has IBC assets available
const accountAddress = 'cheqd1sender...';
const ibcBalances = await checkIBCBalances(accountAddress);
if (ibcBalances.length === 0) {
throw new Error('No IBC tokens available. Please bridge assets from Osmosis first.');
}
// 2. Query host chain configuration
const hostConfig = await sdk.querier[defaultFeeabstractionExtensionKey].hostChainConfig({});
console.log('Host chain config:', hostConfig);
// 3. Query current module balances
const moduleBalances = await sdk.querier[defaultFeeabstractionExtensionKey].feeabsModuleBalances({});
console.log('Module balances:', moduleBalances);
// 4. Use IBC tokens for transaction fees directly
// Fee abstraction automatically handles the conversion behind the scenes
console.log('Fee abstraction is ready for use with IBC tokens');
console.log('Fee abstraction workflow completed successfully');
} catch (error) {
console.error('Fee abstraction workflow failed:', error);
}
}
QQ 错误处理
async function handleFeeAbstractionErrors() {
try {
// Example: Using fee abstraction in a DID operation
const didCreationResponse = await sdk.createDidDocTx(
'cheqd1sender...',
didDocument,
'key1',
{ amount: [{ denom: 'ibc/ABC123...', amount: '100000' }], gas: '300000' }
);
} catch (error) {
if (error.message.includes('insufficient funds')) {
console.error('Account has insufficient IBC tokens');
console.log('Please bridge more assets from Osmosis');
} else if (error.message.includes('invalid denom')) {
console.error('Invalid IBC denomination provided');
console.log('Check supported IBC denominations');
} else if (error.message.includes('host zone not found')) {
console.error('Host zone not configured for this IBC token');
} else {
console.error('Unexpected fee abstraction error:', error);
}
}
}
与其他模块的整合
收费抽象可以与其他Cheqd SDK模块一起使用:
async function useWithDIDOperations() {
// Create a DID document using fee abstraction for payment
const didDocument = {
// DID document structure
};
// Use IBC tokens for fee payment via fee abstraction
const didCreationResponse = await sdk.createDidDocTx(
'cheqd1creator...',
didDocument,
'key1',
{
amount: [{ denom: 'ibc/ABC123...', amount: '100000' }], // Pay with IBC tokens
gas: '300000'
}
);
console.log('DID created with fee abstraction:', didCreationResponse.transactionHash);
}
最佳做法
- 第一桥中型散货箱资产:确保您在尝试使用付费抽象之前, 已经连接了 Osmosis 所需的中型散货箱标志
- 检查账户余额: 检查您的账户在交易前有足够的 IBC 令牌余额
- 处理中型散货箱延迟: 计算应用程序流中的 IBC 令牌传输延迟
- 验证主机区: 总是在使用 IBC 令牌前验证主机区域配置是否适当
- 恢复错误:对网络和符号相关问题实施强有力的错误处理
- 气体估计: 使用适当的气体限制进行费用抽象交易
- 支持的警告: 跟踪支持中型散货箱面额的收费抽象
关于收费抽象概念和执行的更详细资料,请访问 收费抽象文档。 。 。 .
QQ 开发者指南
在无害环境管理项目中安装
在需要建立无害环境管理的项目中安装国家防范机制一揽子计划,利用我们 latest 释放频道以安装稳定版本 :
npm install @cheqd/sdk@latest
要安装 beta 释放,用我们的 -develop 联合国 beta 频道 :
npm install @cheqd/sdk@beta
在共同JS项目中安装
在需要共同JS建设的项目中安装这一国家防范机制软件包,利用我们 cjs 释放频道以安装最新的稳定普通JS版本 :
npm install @cheqd/sdk@cjs
页:1
我们 产品文件网站 解释一下如何 @cheqd/sdk 实值 在Veramo SDK中消费的 (作为该套件如何被消耗的例子).
社区
我们 Discord 服务器 是我们开源社区、软件开发者和节点运营商的主要聊天渠道.
请与我们接触 在那里讨论,帮助, 和反馈项目.