Skip to content

Protocol Deployments Package

@zoralabs/protocol-deployments is a typescript package that provides contract ABIs, deployed addresses, and typescript types for the Zora contracts. These bundled configs and ABIs can be used in conjunction with wagmi or viem to interact with the Zora contracts in typescript.

Installation

To add @zoralabs/protocol-deployments to your project, install the required package:

pnpm
pnpm add @zoralabs/protocol-deployments

Importing Contract ABIs

The package exports a set of contract ABIs for the Zora Protocol. These can be imported and used as follows:

import {
  protocolRewardsABI,
  zoraCreator1155FactoryImplABI,
} from "@zoralabs/protocol-deployments";

Importing Contract Addresses

The package exports addresses each Zora contract is deployed to on each chain.

import {
  protocolRewardsAddress,
  zoraCreator1155FactoryImplAddress,
} from "@zoralabs/protocol-deployments";
import { zora } from "viem/chains";
 
// get addresses contracts are deployed on the Zora chain
const protocolRewardsAddressOnZora = protocolRewardsAddress[zora.id];
const zoraCreator1155FactoryImplAddressOnZora =
  zoraCreator1155FactoryImplAddress[zora.id];

Usage with React wagmi Hooks

The bundled contract ABIs and addresses can be used in conjunction with wagmi to interact with contracts in a typesafe manner in React Apps with minimal code.

First, install @tanstack/react-query with @zoralabs/protocol-deployments:

pnpm
pnpm add @zoralabs/protocol-deployments @tanstack/react-query

wagmi hooks like useReadContract and useWriteContract can be used in conjunction with the contract ABIs and addresses:

index.tsx
import {
  useAccount,
  useChainId,
  useReadContract,
  useWriteContract,
} from "wagmi";
import { Address, formatEther } from "viem";
import {
  protocolRewardsABI,
  protocolRewardsAddress,
} from "@zoralabs/protocol-deployments";
 
export function App() {
  const chainId = useChainId();
  const { address } = useAccount();
 
  // read the balance of an account on the ProtocolRewards contract
  const { data: accountBalance, isLoading } = useReadContract({
    abi: protocolRewardsABI,
    address:
      protocolRewardsAddress[chainId as keyof typeof protocolRewardsAddress],
    functionName: "balanceOf",
    args: [address as Address],
  });
 
  // account that will receive the withdrawn funds
  const recipient = "0x393FF77D5FA5BaB6f6204E6FBA0019D3F25ab133";
 
  // withdraw amount is half of the balance
  const withdrawAmount = (accountBalance || 0n) / 2n;
 
  const { data: hash, writeContract, isPending, isError } = useWriteContract();
 
  async function submit(e: React.FormEvent<HTMLFormElement>) {
    e.preventDefault();
    // write to the withdraw function on the ProtocolRewards contract
    writeContract({
      abi: protocolRewardsABI,
      address:
        protocolRewardsAddress[chainId as keyof typeof protocolRewardsAddress],
      functionName: "withdraw",
      args: [recipient, withdrawAmount],
    });
  }
 
  if (isLoading) return null;
  return (
    <form onSubmit={submit}>
      <p>Account balance: (data)</p>
      <button type="submit" disabled={isPending || isError}>
        Withdraw {formatEther(withdrawAmount)} ETH
      </button>
      {hash && <div>Transaction Hash: {hash}</div>}
    </form>
  );
}

Usage with viem

The bundled contract ABIs and addresses can be used in conjunction with viem to interact with contracts in a typesafe manner with minimal code:

index.tsx
import { publicClient, walletClient, account } from "./config";
import {
  protocolRewardsABI,
  protocolRewardsAddress,
} from "@zoralabs/protocol-deployments";
 
// read the balance of an account on the ProtocolRewards contract
const accountBalance = await publicClient.readContract({
  abi: protocolRewardsABI,
  address:
    protocolRewardsAddress[
      publicClient.chain.id as keyof typeof protocolRewardsAddress
    ],
  functionName: "balanceOf",
  args: [account],
});
 
// account that will receive the withdrawn funds
const recipient = "0x393FF77D5FA5BaB6f6204E6FBA0019D3F25ab133";
 
// withdraw amount is half of the balance
const withdrawAmount = (accountBalance || 0n) / 2n;
 
// write to the withdraw function on the ProtocolRewards contract to withdraw funds
// to the recipient
await walletClient.writeContract({
  abi: protocolRewardsABI,
  address:
    protocolRewardsAddress[
      publicClient.chain.id as keyof typeof protocolRewardsAddress
    ],
  functionName: "withdraw",
  args: [recipient, withdrawAmount],
  // account to execute the transaction
  account,
});