-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli,create-mud,store,world): add abi-ts to replace typechain (#1403
) Co-authored-by: alvarius <[email protected]>
- Loading branch information
Showing
137 changed files
with
13,854 additions
and
7,703 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
"@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. | ||
|
||
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`: | ||
|
||
```diff | ||
-"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:typechain", | ||
+"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts", | ||
-"build:abi": "forge clean && forge build", | ||
+"build:abi": "rimraf abi && forge build --extra-output-files abi --out abi --skip test script MudTest.sol", | ||
+"build:abi-ts": "mud abi-ts --input 'abi/IWorld.sol/IWorld.abi.json' && prettier --write '**/*.abi.json.d.ts'", | ||
"build:mud": "mud tablegen && mud worldgen", | ||
-"build:typechain": "rimraf types && typechain --target=ethers-v5 out/IWorld.sol/IWorld.json", | ||
``` | ||
|
||
And update your client's `setupNetwork.ts` with: | ||
|
||
```diff | ||
-import { IWorld__factory } from "contracts/types/ethers-contracts/factories/IWorld__factory"; | ||
+import IWorldAbi from "contracts/abi/IWorld.sol/IWorld.abi.json"; | ||
|
||
const worldContract = createContract({ | ||
address: networkConfig.worldAddress as Hex, | ||
- 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(...); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ dist | |
**/artifacts/ | ||
**/abi/ | ||
**/broadcast/ | ||
**/deploys/ | ||
**/deploys/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.