部署合约至Kadena本地开发网报错:无法解析'validate-principal'
Kadena合约部署报错:无法解析
validate-principal函数 问题说明
我正在基于real-world-pact教程在Kadena本地开发网部署合约,已更新部署脚本及对应YAML配置,但部署时触发错误,提示无法解析validate-principal函数——该函数是Pact官方明确的内置函数。
部署脚本(JavaScript)
const deployK = async () => { const detailArgs = ["--local", "k-contract-details"]; const contractDetails = await parseArgs(detailArgs).then(runRequest); if (contractDetails.status === "failure") { console.log( "K contract not found on local Chainweb node. Deploying contract..." ); const deployArgs = [ "--send", "deploy-k-contract", "--signers", "kazora", ]; const deployResult = await parseArgs(deployArgs).then(runRequest); if (deployResult.status === "success") { console.log(`Deployed! Cost: ${deployResult.gas} gas.`); } else { throw new Error( `Failed to deploy contract: ${JSON.stringify( deployResult.error, null, 2 )}` ); } } };
部署配置(deploy-k-contract.yaml)
# This YAML file describes a transaction that, when executed, will deploy the # faucet contract to Chainweb. # # To execute this request (you must have funded the faucet account): # faucet-request --send deploy-faucet-contract --signers k # # Alternately, to fund the faucet account _and_ deploy the contract: # faucet-deploy networkId: "development" type: "exec" # To deploy our contract we need to send its entire contents to Chainweb as a # transaction. When a Chainweb node receives a module it will attempt to # register it in the given namespace. codeFile: "../../k.pact" # The 'data' key is for JSON data we want to include with our transaction. As a # general rule, any use of (read-msg) or (read-keyset) in your contract # indicates data that must be included here. # # Our contract reads the transaction data twice: # - (read-keyset "k-keyset") # - (read-msg "upgrade") data: k-admin-keyset: # On deployment, our contract will register a new keyset on Chainweb named # 'k-keyset. We'll use this keyset to govern the faucet # contract, which means the contract can only be upgraded by this keyset. # # We want the contract to be controlled by our faucet account, which means # our keyset should assert that the k.yaml keys were used to # sign the transaction. The public key below is from the k.yaml # key pair file. keys: - "1b54c9eac0047b10f7f6a6f270f7156fb519ef02c9bb96dc28a4e50c48a468f4" pred: "keys-all" # Next, our contract looks for an 'upgrade' key to determine whether it should # initialize data (for example, whether it should create tables). This request # deploys the contract, so we'll set this to false. upgrade: false signers: # We need the Goliath faucet account to sign the transaction, because we want # the faucet to deploy the contract. This is the Goliath faucet public key. It # should match the keyset above. - public: "1b54c9eac0047b10f7f6a6f270f7156fb519ef02c9bb96dc28a4e50c48a468f4" publicMeta: # The faucet contract only works on chain 0, so that's where we'll deploy it. chainId: "0" # The contract should be deployed by the faucet account, which means the # faucet account is responsible for paying the gas for this transaction. You # must have used the 'fund-faucet-account.yaml' request to fund the faucet # account before you can use this deployment request file. sender: "k" # To determine the gas limit for most requests you can simply execute the Pact # code in the REPL, use (env-gaslog) to measure consumption, and round up the # result. However, deployment is different; you can't simply measure a call to # (load "faucet.pact") as it will provide an inaccurate measure. # # Instead, I first set the gas limit to 150000 (the maximum) and deploy the # contract to our local simulation Chainweb. Then, I recorded the gas # consumption that the node reported and round it up. gasLimit: 65000 gasPrice: 0.0000001 ttl: 600
报错日志
./kazora/run-deploy-contract.js ----- executing 'local' request: kazora-details.yaml ----- Kazora account 1b54c9eac0047b10f7f6a6f270f7156fb519ef02c9bb96dc28a4e50c48a468f4 found with 999.9935 in funds. ----- executing 'local' request: kazora-contract-details.yaml ----- Kazora contract not found on local Chainweb node. Deploying contract... ----- executing 'send' request: deploy-kazora-contract.yaml ----- Received request key: vm4O3YKKj7Ea9nR8D8nPSHuVI7OtHPJzQjk7RA7XZLI Sending POST request with request key to /poll endpoint. May take up to 1 minute and 30 seconds to be mined into a block. Polling every 5 seconds until the transaction has been processed... Waiting (15 seconds elapsed)... Waiting (30 seconds elapsed)... Waiting (45 seconds elapsed)... /home/ripple/git/web3/kazora/run-deploy-contract.js:66 throw new Error( ^ Error: Failed to deploy contract: { "callStack": [ "<interactive>:0:102: module" ], "type": "EvalError", "message": "Cannot resolve \"validate-principal\"", "info": "<interactive>:0:8052" } at deployKazora (/home/ripple/git/web3/kazora/run-deploy-contract.js:66:13) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async main (/home/ripple/git/web3/kazora/run-deploy-contract.js:81:3)
解决方法
1. 检查Pact版本兼容性
validate-principal是Pact 4.0及以上版本新增的内置函数,若本地Chainweb节点使用旧版本Pact,会触发解析错误:
- 运行
pact --version确认CLI版本,同时检查Chainweb节点版本是否匹配教程要求。 - 升级Chainweb节点到支持Pact 4.0+的版本。
2. 确认合约函数引用
确保合约中调用validate-principal无拼写错误,必要时在合约开头显式加载核心模块:
(load "pact:core")
3. 重置本地开发环境
重启本地Chainweb节点并清除旧链数据,避免环境缓存导致的异常。
内容的提问来源于stack exchange,提问作者att
相关产品推荐
相关产品推荐

