diff --git a/.changeset/short-ads-jog.md b/.changeset/short-ads-jog.md new file mode 100644 index 0000000000..7e72bc90de --- /dev/null +++ b/.changeset/short-ads-jog.md @@ -0,0 +1,19 @@ +--- +"@latticexyz/abi-ts": minor +"@latticexyz/cli": minor +--- + +Added a new `@latticexyz/abi-ts` package to generate TS type declaration files (`.d.ts`) for each ABI JSON file. + +This allows you to import your JSON ABI and use it directly with libraries like [viem](https://npmjs.com/package/viem) and [abitype](https://npmjs.com/package/abitype). + +``` +pnpm add @latticexyz/abi-ts +pnpm abi-ts +``` + +By default, `abi-ts` looks for files with the glob `**/*.abi.json`, but you can customize this glob with the `--input` argument, e.g. + +```console +pnpm abi-ts --input 'abi/IWorld.sol/IWorld.abi.json' +``` diff --git a/.changeset/six-cats-agree.md b/.changeset/six-cats-agree.md index 60598aa696..37a38ecd61 100644 --- a/.changeset/six-cats-agree.md +++ b/.changeset/six-cats-agree.md @@ -1,12 +1,8 @@ --- -"@latticexyz/abi-ts": minor -"@latticexyz/cli": minor -"@latticexyz/store": minor -"@latticexyz/world": minor "create-mud": minor --- -Added a new `@latticexyz/abi-ts` package to generate TS type declaration files (`.d.ts`) for each ABI JSON file. This replaces our usage TypeChain everywhere. It's also bundled into `@latticexyz/cli` under the `mud abi-ts` command. +We now use `@latticexyz/abi-ts` to generate TS type declaration files (`.d.ts`) for each ABI JSON file. This replaces our usage TypeChain everywhere. If you have a MUD project created from an older template, you can replace TypeChain with `abi-ts` by first updating your contracts' `package.json`: @@ -31,17 +27,3 @@ And update your client's `setupNetwork.ts` with: - abi: IWorld__factory.abi, + abi: IWorldAbi, ``` - -If you previously relied on TypeChain types from `@latticexyz/store` or `@latticexyz/world`, you will either need to migrate to viem or abitype using ABI JSON imports or generate TypeChain types from our exported ABI JSON files. - -```ts -import { getContract } from "viem"; -import IStoreAbi from "@latticexyz/store/abi/IStore.sol/IStore.abi.json"; - -const storeContract = getContract({ - abi: IStoreAbi, - ... -}); - -await storeContract.write.setRecord(...); -``` diff --git a/.changeset/unlucky-guests-cover.md b/.changeset/unlucky-guests-cover.md new file mode 100644 index 0000000000..65ba957d11 --- /dev/null +++ b/.changeset/unlucky-guests-cover.md @@ -0,0 +1,20 @@ +--- +"@latticexyz/store": minor +"@latticexyz/world": minor +--- + +We now use `@latticexyz/abi-ts` to generate TS type declaration files (`.d.ts`) for each ABI JSON file. This replaces our usage TypeChain everywhere. + +If you previously relied on TypeChain types from `@latticexyz/store` or `@latticexyz/world`, you will either need to migrate to viem or abitype using ABI JSON imports or generate TypeChain types from our exported ABI JSON files. + +```ts +import { getContract } from "viem"; +import IStoreAbi from "@latticexyz/store/abi/IStore.sol/IStore.abi.json"; + +const storeContract = getContract({ + abi: IStoreAbi, + ... +}); + +await storeContract.write.setRecord(...); +```