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

Kadena Pact创建账户失败求助:使用sender00密钥对创建账户报错

Kadena Pact 创建账户失败问题解决

问题情况

我按照官方指引创建coin账户,调用getBalance("sender00")能正常获取余额,但使用sender00的密钥对创建新账户testaccount时操作失败。

正常的getBalance返回结果

{
  "gas": 20,
  "result": {
    "status": "success",
    "data": 99998999.9999446
  },
  "reqKey": "AnmQHR9ciGruzwaV2LksjFANS8Mbr5UBuj26d2w4TLE",
  "logs": "wsATyGqckuIvlm89hhd2j4t6RMkCrcwJe_oeCYr7Th8",
  "metaData": {
    "publicMeta": {
      "creationTime": 1670018678,
      "ttl": 28000,
      "gasLimit": 600,
      "chainId": "0",
      "gasPrice": 1e-7,
      "sender": "368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca"
    },
    "blockTime": 1670018669855184,
    "prevBlockHash": "g5bNGUcMPQYC4klTi-D0QhsMBIT9oggVa_-Ea8hyQq4",
    "blockHeight": 1964
  },
  "continuation": null,
  "txId": null
}

报错信息

Validation failed for hash "iu9bake1-nzhfQuYoRCM_LggDBenBLDWjGf6o7d00kY": Attempt to buy gas failed with: : Failure: Tx Failed: read: row not found: 368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca

相关配置与代码

.env配置文件

SENDER00_PUBLIC=368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca
SENDER00_SECRET=251a920c403ae8c8f65f59142316af3c82b631fba46ddea92ee8c95035bd2898

脚本文件

import * as dotenv from 'dotenv'
dotenv.config()
import Pact from 'pact-lang-api';

const GAS_PRICE = 0.0000001;
const GAS_LIMIT = 400;
const TTL = 28000;
const NETWORK_ID = 'development'//'testnet04';
const CHAIN_ID = '0';
const API_HOST = `http://localhost:8080/chainweb/0.0/${NETWORK_ID}/chain/${CHAIN_ID}/pact`;

const creationTime = () => Math.round((new Date).getTime() / 1000) - 15;

async function getBalance(account) {
  const cmd = {
    networkId: NETWORK_ID,
    keyPairs: KEY_PAIR,
    pactCode: `(coin.get-balance "${account}")`,
    envData: {},
    meta: {
      creationTime: creationTime(),
      ttl: 28000,
      gasLimit: 600,
      chainId: CHAIN_ID,
      gasPrice: 0.0000001,
      sender: KEY_PAIR.publicKey
    }
  };

  const result = await Pact.fetch.local(cmd, API_HOST);
  console.log(JSON.stringify(result, null, 2));
}


const KEY_PAIR = {
  'publicKey': `${process.env.SENDER00_PUBLIC}`,
  'secretKey': `${process.env.SENDER00_SECRET}`
}


async function createAccount(newAccount) {
  const cmd = {
    networkId: NETWORK_ID,
    keyPairs: KEY_PAIR,
    pactCode: `(coin.create-account "${newAccount}" (read-keyset "account-keyset"))`,
    envData: {
      "account-keyset": {
        keys: [
          // Drop the k:
          newAccount.substr(2)
        ],
        pred: "keys-all"
      },
    },
    meta: {
      creationTime: creationTime(),
      ttl: 28000,
      gasLimit: 600,
      chainId: CHAIN_ID,
      gasPrice: 0.0000001,
      sender: KEY_PAIR.publicKey
    }
  };

  const response = await Pact.fetch.send(cmd, API_HOST);
  if (!response.requestKeys)
  {
    return console.error(response)
  }
  console.log(`Request key: ${response.requestKeys[0]}`);
  console.log("Transaction pending...");
  const txResult = await Pact.fetch.listen(
    { listen: response.requestKeys[0] },
    API_HOST
  );
  console.log("Transaction mined!");
  console.log(txResult);
}


await getBalance(`sender00`) // OK
await createAccount(`testaccount`)

问题原因与修复方案

报错提示找不到对应公钥的行,核心问题是交易meta中的sender字段填错了:Kadena要求sender填写的是账户名称(比如sender00),而不是账户对应的公钥。因为购买gas时需要从指定账户扣除余额,账户是通过名称而非公钥来识别的。

修改后的代码部分

需要将getBalance和createAccount函数中meta.sender的值改为账户名sender00:

修改getBalance函数的meta部分

meta: {
  creationTime: creationTime(),
  ttl: 28000,
  gasLimit: 600,
  chainId: CHAIN_ID,
  gasPrice: 0.0000001,
  sender: "sender00" // 替换为账户名,而非公钥
}

修改createAccount函数的meta部分

meta: {
  creationTime: creationTime(),
  ttl: 28000,
  gasLimit: 600,
  chainId: CHAIN_ID,
  gasPrice: 0.0000001,
  sender: "sender00" // 替换为账户名,而非公钥
}

修改后重新执行脚本,即可正常创建新账户。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 15:55:27