Search code examples
pact-langkadena

Deploying contract to Kadena localdevnet error: "Cannot resolve 'validate-principle'"


I'm following https://github.com/thomashoneyman/real-world-pact/ to deploy my contract on local devnet.

I've updated the deployment script as

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
        )}`
      );
    }
  }
};

The deploy-k-contracty.yaml is

# 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

It complains about validate-principal function, however it's defined as pact built-in function.

https://pact-language.readthedocs.io/en/stable/pact-functions.html?highlight=validate-principal#validate-principal

./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)

Solution

  • Make sure you are using version 4.3.1 of pact or later. The build-in function was only added at that point: https://github.com/kadena-io/pact/releases/tag/v4.3.1