Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 54 additions & 29 deletions scripts/disputeIp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,21 @@ import { Address, http, toHex } from 'viem'
import { mintNFT } from './utils/mintNFT'
import { NFTContractAddress, RPCProviderUrl, account } from './utils/utils'

// BEFORE YOU RUN THIS FUNCTION: Make sure to read the README which contains
// instructions for running this "Simple Mint and Register" example.
// BEFORE RUNNING: Ensure proper setup as per the README instructions.

const main = async function () {
// 1. Set up your Story Config
//
// Docs: https://docs.story.foundation/docs/typescript-sdk-setup
const config: StoryConfig = {
account: account,
transport: http(RPCProviderUrl),
chainId: 'odyssey',
}
const client = StoryClient.newClient(config)
const validateSetup = () => {
if (!RPCProviderUrl) throw new Error('RPCProviderUrl is not set.')
if (!NFTContractAddress) throw new Error('NFTContractAddress is not set.')
if (!account || !account.address) throw new Error('Account configuration is missing.')
}

// 2. Register an IP Asset
//
// Docs: https://docs.story.foundation/docs/register-an-nft-as-an-ip-asset
const tokenId = await mintNFT(account.address, 'test-uri')
const ipResponse: RegisterIpAndAttachPilTermsResponse = await client.ipAsset.registerIpAndAttachPilTerms({
const registerIpAsset = async (
client: StoryClient,
tokenId: string // Ensure this expects a string
): Promise<RegisterIpAndAttachPilTermsResponse> => {
return await client.ipAsset.registerIpAndAttachPilTerms({
nftContract: NFTContractAddress,
tokenId: tokenId!,
tokenId: tokenId, // Now safely passed as a string
terms: [],
ipMetadata: {
ipMetadataURI: 'test-uri',
Expand All @@ -33,20 +27,51 @@ const main = async function () {
},
txOptions: { waitForTransaction: true },
})
console.log(`Root IPA created at transaction hash ${ipResponse.txHash}, IPA ID: ${ipResponse.ipId}`)
console.log(`View on the explorer: https://explorer.story.foundation/ipa/${ipResponse.ipId}`)

// 3. Raise a Dispute
//
// Docs: https://docs.story.foundation/docs/dispute-module
const disputeResponse = await client.dispute.raiseDispute({
targetIpId: ipResponse.ipId as Address,
// this is "PLAGIARISM" in base32, and is currently the only whitelisted
// tag for protocol v1.2
}

const raiseDispute = async (client: StoryClient, ipId: Address) => {
return await client.dispute.raiseDispute({
targetIpId: ipId,
// "PLAGIARISM" in base32, currently the only whitelisted tag for protocol v1.2
targetTag: '0x504c414749415249534d00000000000000000000000000000000000000000000',
cid: 'QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR',
})
console.log(`Dispute raised at transaction hash ${disputeResponse.txHash}, Dispute ID: ${disputeResponse.disputeId}`)
}

const main = async function () {
try {
// 1. Validate setup
validateSetup()

// 2. Set up Story Config
console.log('Setting up Story configuration...')
const config: StoryConfig = {
account: account,
transport: http(RPCProviderUrl),
chainId: 'odyssey', // Change if you're using a different chain.
}
const client = StoryClient.newClient(config)

// 3. Mint an NFT
console.log('Minting NFT...')
const tokenId = await mintNFT(account.address, 'test-uri')
if (!tokenId) throw new Error('Failed to mint NFT.')

// 4. Register IP Asset
console.log('Registering IP Asset...')
const ipResponse = await registerIpAsset(client, tokenId.toString())
console.log(`Root IPA created at transaction hash: ${ipResponse.txHash}`)
console.log(`IPA ID: ${ipResponse.ipId}`)
console.log(`View on the explorer: https://explorer.story.foundation/ipa/${ipResponse.ipId}`)

// 5. Raise a Dispute
console.log('Raising a dispute...')
const disputeResponse = await raiseDispute(client, ipResponse.ipId as Address)
console.log(`Dispute raised at transaction hash: ${disputeResponse.txHash}`)
console.log(`Dispute ID: ${disputeResponse.disputeId}`)
} catch (error) {
console.error('An error occurred:', error)
}
}

main()