Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export/typescript abi 2 #212

Closed
wants to merge 12 commits into from
Closed
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/clients @immutable/assets
/abi @immutable/assets

/contracts/allowlist @immutable/assets
/contracts/token @immutable/assets
Expand Down
66 changes: 48 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Immutable Contracts is a library of smart contracts targeted at developers who w

- Token presets, e.g. ERC721

- [ImmutableERC721](./contracts/token/erc721/preset/ImmutableERC721.sol)
- [ImmutableERC721MintByID](./contracts/token/erc721/preset/ImmutableERC721MintByID.sol)
- [ImmutableERC1155](./contracts/token/erc1155/preset/ImmutableERC1155.sol)
- [ImmutableERC20MinterBurnerPermit](./contracts/token/erc20/preset/ImmutableERC20MinterBurnerPermit.sol)
- [ImmutableERC20FixedSupplyNoBurn](./contracts/token/erc20/preset/ImmutableERC20FixedSupplyNoBurn.sol)
- [ImmutableERC721](./contracts/token/erc721/preset/ImmutableERC721.sol)
- [ImmutableERC721MintByID](./contracts/token/erc721/preset/ImmutableERC721MintByID.sol)
- [ImmutableERC1155](./contracts/token/erc1155/preset/ImmutableERC1155.sol)
- [ImmutableERC20MinterBurnerPermit](./contracts/token/erc20/preset/ImmutableERC20MinterBurnerPermit.sol)
- [ImmutableERC20FixedSupplyNoBurn](./contracts/token/erc20/preset/ImmutableERC20FixedSupplyNoBurn.sol)

- Bridging contracts

Expand Down Expand Up @@ -65,24 +65,54 @@ contract MyERC721 is ImmutableERC721 {
}
```

#### SDK client
#### Typescript ABIs

`contracts` comes with a Typescript SDK client that can be used to interface with Immutable preset contracts:
`contracts` comes with importable Typescript ABIs that can be used to generate a contract client in conjunction with libraries such as `viem` or `wagmi`, so that you can
interact with deployed preset contracts.

- ImmutableERC721
- ImmutableERC721MintByID
The following Typescript ABIs are available:

To import and use the ImmutableERC721 contract client:
- `ImmutableERC721Abi`
- `ImmutableERC721MintByIdAbi`

```typescript
import { ERC721Client } from "@imtbl/contracts";

const contractAddress = YOUR_CONTRACT_ADDRESS;
An example of how to create and use a contract client in order to interact with a deployed `ImmutableERC721`:

const client = new ERC721Client(contractAddress);

const mintTransaction = await client.populateMint(receiver, 1);
const tx = await signer.sendTransaction(mintTransaction);
```typescript
import { getContract, http, createWalletClient, defineChain } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { ImmutableERC721MintByIdAbi } from "@imtbl/contracts";

const PRIVATE_KEY = "YOUR_PRIVATE_KEY"; // should be read from environment variable
const CONTRACT_ADDRESS = "YOUR_CONTRACT_ADDRESS"; // should be of type `0x${string}`
const RECIPIENT = "ACCOUNT_ADDRESS"; // should be of type `0x${string}`
const TOKEN_ID = BigInt(1);

const immutableTestnet = defineChain({
id: 13473,
name: "imtbl-zkevm-testnet",
nativeCurrency: { name: "IMX", symbol: "IMX", decimals: 18 },
rpcUrls: {
default: {
http: ["https://rpc.testnet.immutable.com"],
},
},
});

const walletClient = createWalletClient({
chain: immutableTestnet,
transport: http(),
account: privateKeyToAccount(`0x${PRIVATE_KEY}`),
});

// Bound contract instance
const contract = getContract({
address: CONTRACT_ADDRESS,
abi: ImmutableERC721MintByIdAbi,
client: walletClient,
});

const txHash = await contract.write.mint([recipient, tokenId]);
console.log(`txHash: ${txHash}`);
```

## Build and Test
Expand Down
20 changes: 20 additions & 0 deletions abi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Typescript ABIs

The `contracts` repo exports Typescript ABIs for customers to generate their own contract clients using modern libraries such as `abitype`, `viem` and `wagmi`, for interacting with deployed preset contracts.

## Adding a new Typescript ABI

Typescript ABIs are generated using `@wagmi/cli` and `foundry` build files:

- `@wagmi/cli` configuration can be found in file `wagmi.config.ts`
- `foundry` build files are available in this repo once built at folder `foundry-out`

To add a new Typescript ABI:

- Ensure the JSON ABI is available in folder `foundry-out`
- Update the configuration in `wagmi.config.ts` to add the ABI to the `contracts` array
- Run command `yarn wagmi generate` from the root of the folder
- Ensure the new Typescript ABI is available in `abi/generated.ts`
- Update `abi/index.ts` to rename and export Typescript ABI

The next published version will contain the new Typescript ABI.
Loading
Loading