Skip to content

Creating an 1155 with a split payout

0xSplits can be used to split the payout for 1155s among multiple recipients. This is done by first creating a 0xSplit recipient contract at a deterministic address based on the recipient addresses and the split percentages, and then creating the 1155 token with the 0xSplit recipient contract as the payout recipient. Due to security limitations, this must be done in two separate transactions. Note: splits are not currently supported with Premints, and are only supported with onchain creation using create1155().

Here is an example using the 0xSplits SDK:

example.ts
import { createCreatorClient } from "@zoralabs/protocol-sdk";
import { publicClient, walletClient, chainId, creatorAccount } from "./config";
import { SplitV1Client, SplitRecipient } from "@0xsplits/splits-sdk";
import { Address, Chain, HttpTransport, PublicClient } from "viem";
import { contract } from "./data";
 
/* ==== 1. Create the split ===== */
 
// setup a splits client
const splitsClient = new SplitV1Client({
  chainId,
  publicClient: publicClient as PublicClient<HttpTransport, Chain>,
  apiConfig: {
    // This is a dummy 0xSplits api key, replace with your own
    apiKey: "123456",
  },
});
 
// configure the split - the first recipient gets 70% of the payout,
// the second gets 30 %
const splitsConfig: {
  recipients: SplitRecipient[];
  distributorFeePercent: number;
} = {
  recipients: [
    {
      address: "0xDADe31b9CdA249f9C241114356Ba81349Ca920aB",
      percentAllocation: 70,
    },
    {
      address: "0xbC4D657fAbEe03181d07043E00dbC5751800Ee05",
      percentAllocation: 30,
    },
  ],
  distributorFeePercent: 0,
};
 
// get the deterministic split address, and determine if it has been created or not.
const predicted = await splitsClient.predictImmutableSplitAddress(splitsConfig);
 
if (!predicted.splitExists) {
  // if the split has not been created, create it by getting the transaction to execute
  // and executing it with the wallet client
  const { data, address } =
    await splitsClient.callData.createSplit(splitsConfig);
 
  await walletClient.sendTransaction({
    to: address as Address,
    account: creatorAccount,
    data,
  });
}
 
const splitRecipient = predicted.splitAddress;
 
/* ==== 2. Create the 1155 with the splits recipient as the payoutRecipient ===== */
 
const creatorClient = createCreatorClient({ chainId, publicClient });
 
const { parameters } = await creatorClient.create1155({
  contract,
  token: {
    tokenMetadataURI: "ipfs://DUMMY/token.json",
    payoutRecipient: splitRecipient,
  },
  account: creatorAccount,
});
 
// simulate the transaction
const { request } = await publicClient.simulateContract(parameters);
 
// execute the transaction
await walletClient.writeContract(request);