Skip to main content

CampaignInfoFactory

Deploys new CampaignInfo contracts. Each campaign gets its own on-chain CampaignInfo instance with its own address, NFT collection, and configuration.

const factory = oak.campaignInfoFactory('0x...contractAddress');

Methods

Reads

MethodReturnsDescription
identifierToCampaignInfo(identifierHash)AddressGet CampaignInfo address by identifier hash
isValidCampaignInfo(campaignInfo)booleanCheck if an address is a valid CampaignInfo
owner()AddressContract owner

Writes

MethodReturnsDescription
createCampaign(params)HexDeploy a new CampaignInfo contract
updateImplementation(newImplementation)HexUpdate the CampaignInfo implementation address
transferOwnership(newOwner)HexTransfer contract ownership
renounceOwnership()HexRenounce contract ownership

CreateCampaignParams

The createCampaign method accepts a params object:

FieldTypeDescription
creatorAddressAddress of the campaign creator
identifierHashHexbytes32 unique campaign identifier hash
selectedPlatformHashHex[]Platform hashes selected for this campaign
platformDataKeyHex[]Optional platform-specific data keys
platformDataValueHex[]Optional platform-specific data values
campaignDataCreateCampaignDataOn-chain campaign configuration
nftNamestringERC-721 collection name for pledge NFTs
nftSymbolstringERC-721 collection symbol
nftImageURIstringIPFS or HTTPS URI for the NFT image
contractURIstringIPFS or HTTPS URI for ERC-721 contract metadata

CampaignData

FieldTypeDescription
launchTimebigintUnix timestamp (seconds) when the campaign launches
deadlinebigintUnix timestamp (seconds) when the campaign ends
goalAmountbigintMinimum funding goal in currency units
currencyHexbytes32 currency identifier

Usage examples

Create a campaign

import {
keccak256,
toHex,
getCurrentTimestamp,
addDays,
} from '@oaknetwork/contracts-sdk';

const PLATFORM_HASH = keccak256(toHex('my-platform'));
const CURRENCY = toHex('USD', { size: 32 });
const identifierHash = keccak256(toHex('my-campaign-slug'));
const now = getCurrentTimestamp();

const txHash = await factory.createCampaign({
creator: '0x...creatorAddress',
identifierHash,
selectedPlatformHash: [PLATFORM_HASH],
campaignData: {
launchTime: now + 3_600n, // 1 hour from now
deadline: addDays(now, 30), // 30 days from now
goalAmount: 1_000_000n,
currency: CURRENCY,
},
nftName: 'My Campaign NFT',
nftSymbol: 'MCN',
nftImageURI: 'https://example.com/nft.png',
contractURI: 'https://example.com/contract.json',
});

const receipt = await oak.waitForReceipt(txHash);

Discover the deployed CampaignInfo address

After createCampaign, the factory emits a CampaignCreated event that carries the new CampaignInfo address. Two approaches are available — prefer the receipt-based one.

Approach 1 — Decode the CampaignCreated event from the receipt (recommended). Deterministic and works immediately regardless of RPC indexing lag.

import { CAMPAIGN_INFO_FACTORY_EVENTS } from '@oaknetwork/contracts-sdk';

let campaignInfoAddress: `0x${string}` | undefined;

for (const log of receipt.logs) {
try {
const decoded = factory.events.decodeLog({
topics: log.topics as [`0x${string}`, ...`0x${string}`[]],
data: log.data as `0x${string}`,
});

if (decoded.eventName === CAMPAIGN_INFO_FACTORY_EVENTS.CampaignCreated) {
campaignInfoAddress = decoded.args?.campaignInfoAddress as `0x${string}`;
break;
}
} catch {
// Log belongs to a different contract — skip
}
}

console.log('CampaignInfo (from receipt):', campaignInfoAddress);

Approach 2 — Lookup via identifierToCampaignInfo (convenience). Handy when you only have the identifier and did not keep the receipt. On some RPC providers the mapping may briefly return the zero address right after the transaction, so prefer Approach 1 when the receipt is available.

const campaignAddress = await factory.identifierToCampaignInfo(identifierHash);
console.log('CampaignInfo (from lookup):', campaignAddress);

Verify a campaign address

const isValid = await factory.isValidCampaignInfo('0x...someAddress');
console.log('Is valid campaign:', isValid);

Simulate before creating

try {
await factory.simulate.createCampaign(params);
// Safe to proceed
const txHash = await factory.createCampaign(params);
} catch (err) {
console.error('Would revert:', err.name);
}