Help developers write code that interacts with Alkahest escrow contracts using the TypeScript, Rust, or Python SDK
当开发者需要编写与 Alkahest 托管合约交互的代码时使用此技能。涵盖范围包括:
| SDK | 语言 | 包名 | 基础库 |
|---|---|---|---|
| TypeScript | TypeScript/JavaScript | @alkahest/ts-sdk | viem |
| Rust |
typescript
import { createWalletClient, http } from viem;
import { privateKeyToAccount } from viem/accounts;
import { baseSepolia } from viem/chains;
import { makeClient } from @alkahest/ts-sdk;
const walletClient = createWalletClient({
account: privateKeyToAccount(0x私钥),
chain: baseSepolia,
transport: http(https://rpc-url),
});
// 包含所有扩展的完整客户端
const client = makeClient(walletClient);
// 自定义地址(可选)
const client = makeClient(walletClient, customAddresses);
// 用于自定义扩展模式的最小化客户端
const minimal = makeMinimalClient(walletClient);
const extended = minimal.extend((base) => ({
custom: makeErc20Client(base.viemClient, pickErc20Addresses(base.contractAddresses)),
}));
rust
use alkahest_rs::AlkahestClient;
// 包含所有扩展的完整客户端(默认 Base Sepolia)
let client = AlkahestClient::withbaseextensions(
0x私钥,
https://rpc-url,
None, // 使用 Base Sepolia 地址
).await?;
// 自定义地址
use alkahestrs::{DefaultExtensionConfig, ETHEREUMSEPOLIA_ADDRESSES};
let client = AlkahestClient::withbaseextensions(
0x私钥,
https://rpc-url,
Some(ETHEREUMSEPOLIAADDRESSES),
).await?;
// 裸客户端 + 自定义扩展
let bare = AlkahestClient::new(0x私钥, https://rpc-url).await?;
let extended = bare.extend::
python
from alkahest_py import PyAlkahestClient
TypeScript:
typescript
// 1. 授权代币
await client.erc20.util.approve({ address: 代币地址, value: 金额 }, escrow);
// 2. 创建托管
const { hash, attested } = await client.erc20.escrow.nonTierable.doObligation(
client.erc20.escrow.nonTierable.encodeObligationRaw({
token: 代币地址, amount: 金额, arbiter: 仲裁器地址, demand: 需求字节,
}),
);
const escrowUid = attested.uid;
Rust:
rust
// 1. 授权
client.erc20().approve(&Erc20Data { address: token, value: amount }, ApprovalPurpose::Escrow).await?;
// 2. 创建托管
let receipt = client.erc20().escrow().nontierable().makestatement(
token, amount, arbiter, demand_bytes, expiration,
).await?;
let attested = client.getattestedevent(receipt)?;
Python:
python
TypeScript:
typescript
const { attested } = await client.stringObligation.doObligation(
履行内容,
undefined, // schema
escrowUid, // refUID
);
Rust:
rust
let receipt = client.stringobligation().doobligation(
履行内容, None, Some(escrow_uid),
).await?;
Python:
python
uid = await client.stringobligation.doobligation(
履行内容,
refuid=escrowuid,
)
TypeScript:
typescript
const { hash } = await client.erc20.escrow.nonTierable.collectObligation(
escrowUid,
fulfillmentUid,
);
Rust:
rust
let receipt = client.erc20().escrow().nontierable().collectpayment(
escrowuid, fulfillmentuid,
).await?;
Python:
python
txhash = await client.erc20.escrow.nontierable.collect(escrowuid, fulfillmentuid)
TypeScript:
typescript
const result = await client.waitForFulfillment(
client.contractAddresses.erc20EscrowObligation,
escrowUid,
);
Rust:
rust
let log = client.waitforfulfillment(
client.erc20_address(Erc20Contract::EscrowObligation),
escrow_uid,
None, // from_block
).await?;
Python:
python
result = await client.waitforfulfillment(
escrowcontractaddress,
escrow_uid,
)
TypeScript:
typescript
// 可信预言机
const demand = client.arbiters.general.trustedOracle.encodeDemand({
oracle: 预言机地址, data: 0x,
});
// 逻辑组合
const demand = client.arbiters.logical.all.encodeDemand({
arbiters: [仲裁器A, 仲裁器B],
demands: [需求A, 需求B],
});
// 证明属性
const demand = client.arbiters.attestationProperties.attester.encodeDemand({
attester: 所需证明者,
});
Rust:
rust
// 可信预言机(ABI 编码)
use alloy::sol_types::SolValue;
let demand = TrustedOracleArbiter::DemandData { oracle, data: Bytes::new() }.abi_encode();
// 解码仲裁器需求(自动检测)
let decoded = client.arbiters().decodearbiterdemand(arbiteraddr, &demandbytes)?;
Python:
python
TypeScript:
typescript
// 1. 计算承诺
const commitment = await client.commitReveal.computeCommitment(
escrowUid, claimerAddress, { payload, salt, schema },
);
// 2. 提交(以 ETH 形式发送保证金)
await client.commitReveal.commit(commitment);
// 3. 等待 1+ 个区块,然后揭示
const { attested } = await client.commitReveal.doObligation(
{ payload, salt, schema }, escrowUid,
);
// 4. 收回保证金
await client.commitReveal.reclaimBond(attested.uid);
Rust:
rust
let commitment = client.commitreveal().computecommitment(
escrowuid, claimer, &obligationdata,
).await?;
client.commit_reveal().commit(commitment).await?;
// 等待 1+ 个区块
let receipt = client.commitreveal().doobligation(&obligationdata, Some(escrowuid)).await?;
client.commitreveal().reclaimbond
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 alkahest-developer-1776110769 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 alkahest-developer-1776110769 技能
skillhub install alkahest-developer-1776110769
文件大小: 16.77 KB | 发布时间: 2026-4-14 16:04