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';

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);

// Look up the deployed CampaignInfo address
const campaignAddress = await factory.identifierToCampaignInfo(identifierHash);
console.log('Campaign deployed at:', 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);
}