Preparation
In the following examples, we will interact with the coin contract. To have
better type support, we strongly recommend generating the type definition from
the contract using @kadena/pactjs-cli.
To install @kadena/pactjs-cli as a dev dependency for your project, run the
following command in the terminal:
npm install @kadena/pactjs-cli --save-devnpm install @kadena/pactjs-cli --save-devYou can generate type definitions from either a local file or directly from the chain.
Creating a type definition from a contract deployed on the chain
npx pactjs contract-generate --contract="coin" --api https://api.chainweb.com/chainweb/0.0/mainnet01/chain/1/pactnpx pactjs contract-generate --contract="coin" --api https://api.chainweb.com/chainweb/0.0/mainnet01/chain/1/pactCreating a type definition from a pact file
npx pactjs contract-generate --file=./coin.pact --api https://api.chainweb.com/chainweb/0.0/mainnet01/chain/1/pactnpx pactjs contract-generate --file=./coin.pact --api https://api.chainweb.com/chainweb/0.0/mainnet01/chain/1/pactif your contract has dependency to other modules you should either pass those
modules with --file or if they are already deployed on the chain you can use
--api to let the script fetch them from the chain. So for the coin example you
can alternatively use the following command if you have all of the files
locally.
npx pactjs contract-generate --file=./coin.pact --file=./fungible-v2.pact --file=./fungible-xchain-v1.pactnpx pactjs contract-generate --file=./coin.pact --file=./fungible-v2.pact --file=./fungible-xchain-v1.pactNote: You can use --file and --contract several times, and even together.
Tip: Remember to persist the generated types by adding the command as a npm scripts.