import { CdpClient } from "@coinbase/cdp-sdk";
import { type Address, encodeFunctionData } from "viem";
import { zoraCreator1155ImplABI } from '@zoralabs/protocol-deployments';
// Initialize CDP client
const cdp = new CdpClient({
apiKeyId: process.env.CDP_API_KEY_ID,
apiKeySecret: process.env.CDP_API_KEY_SECRET,
walletSecret: process.env.CDP_WALLET_SECRET,
});
// Create account and smart account
const evmAccount = await cdp.evm.createAccount();
const smartAccount = await cdp.evm.createSmartAccount({
owner: evmAccount,
});
// Token details
const tokenId = 1n;
const tokenMetadataURI = "ar://your-arweave-metadata";
const contractUri = "ar://your-contract-metadata";
const collectionName = "My Amazing Collection";
// Setup actions
const setupActions = [
// Setup the token
encodeFunctionData({
abi: zoraCreator1155ImplABI,
functionName: 'setupNewToken',
args: [tokenMetadataURI, 100n], // 100 max supply
}),
// Update token URI
encodeFunctionData({
abi: zoraCreator1155ImplABI,
functionName: 'updateTokenURI',
args: [tokenId, tokenMetadataURI],
}),
// Set royalties
encodeFunctionData({
abi: zoraCreator1155ImplABI,
functionName: 'updateRoyaltiesForToken',
args: [
tokenId,
{
royaltyBPS: 1000, // 10%
royaltyRecipient: smartAccount.address,
},
],
}),
];
// Create the collection with setup actions
const createContractData = encodeFunctionData({
abi: tokenAbi, // Your token contract ABI
functionName: "createContract",
args: [
contractUri,
collectionName,
{
royaltyMintSchedule: 0,
royaltyBPS: 1000,
royaltyRecipient: smartAccount.address,
},
smartAccount.address,
setupActions,
],
});
// Send the transaction
const sendResult = await cdp.evm.sendUserOperation({
smartAccount,
network: "base-sepolia",
paymasterUrl: process.env.CDP_PAYMASTER_URL,
calls: [
{
to: "0x6832A997D8616707C7b68721D6E9332E77da7F6C" as Address,
data: createContractData,
},
],
});
// Complete the transaction processing
// ... rest of the code ...