You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Tezos区块链构建、签名并广播交易时遇到问题求助

Tezos交易构建、签名与广播问题解决

一、Reveal交易的请求URL与正确构造

Reveal操作的锻造和普通交易用的是同一个RPC端点:${rpcUrl}/chains/main/blocks/head/helpers/forge/operations。你只需要把reveal操作放在contents数组里即可,但要补上两个关键字段:

  • 必须添加source字段,值为你的地址sourceAddr,否则RPC会报错
  • counter要取你的地址当前计数器加1的值,可通过请求${rpcUrl}/chains/main/blocks/head/context/contracts/${sourceAddr}/counter获取正确数值

正确的Reveal锻造请求示例:

// 先获取地址当前计数器
const counterRes = await axios.get(`${rpcUrl}/chains/main/blocks/head/context/contracts/${sourceAddr}/counter`);
const nextCounter = (Number(counterRes.data) + 1).toString();

// 锻造Reveal操作
let revealBinary = await axios({
  method: "post",
  url: `${rpcUrl}/chains/main/blocks/head/helpers/forge/operations`,
  data: {
    branch: mostRecentBlock,
    contents: [
      {
        kind: "reveal",
        source: sourceAddr,
        fee: "1",
        counter: nextCounter,
        public_key: TezBridgeCrypto.crypto.getKeyFromSeed(random_seed).getPublicKey(),
        gas_limit: "10500",
        storage_limit: "0",
      },
    ],
  },
  headers: {
    "Content-type": "application/json",
  },
});

二、注入请求无返回数据的排查与修复

你的注入请求存在两个核心问题:

  1. Content-Type错误:注入的injectionData是十六进制字符串,不是JSON,所以headers里的Content-type要改为text/plain
  2. 异步参数格式错误:async参数需显式写为async=true,若想同步获取结果,直接去掉async参数即可

修正后的注入请求示例:

// 同步模式(推荐,会返回操作哈希或错误信息)
const injectRes = await axios({
  method: "post",
  url: `${rpcUrl}/injection/operation?chain=test`,
  data: injectionData,
  headers: {
    "Content-type": "text/plain",
  },
});

// 打印返回结果,确认操作状态
console.log("注入结果:", injectRes.data); // 成功返回操作哈希,失败返回错误详情

额外注意点:

  • 签名时的0x03是Tezos操作的正确前缀,但要确保binaryFromRpc.data是RPC返回的纯十六进制字符串,无多余前缀/后缀
  • 确认你的RPC节点确实对应测试网,chain=test参数才有效

内容的提问来源于stack exchange,提问作者Quintin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 11:35:23