@gotake/gotake-sdk
Version:
SDK for interacting with GoTake blockchain contracts
94 lines (93 loc) • 3.17 kB
JavaScript
import { ethers } from 'ethers';
import { BaseApi } from './base-api.js';
import { IPNFTWrapper } from '../wrappers/index.js';
/**
* IPNFT API module, providing functionality related to IP NFT minting
*/
export class IPNFTApi extends BaseApi {
/**
* Create IPNFT API instance
* @param provider Provider instance
* @param signer Signer instance
*/
constructor(provider, signer) {
super(provider, signer);
this._ipnftWrapper = new IPNFTWrapper(provider, signer);
}
/**
* Mint IP NFT
* @param to Recipient address
* @param metadata Content metadata
* @param options Transaction options
* @returns Transaction object and token ID
*/
async mint(to, metadata, options) {
await this._ipnftWrapper.init();
const { title, description = '', thumbnailUrl = '' } = metadata;
// Create metadata URI (typically IPFS URL, simplified example here)
const uri = thumbnailUrl || `ipfs://example/${title.replace(/\s+/g, '-').toLowerCase()}`;
// Convert VideoMetadata to MediaMetadata
const mediaMetadata = {
title: title || 'Untitled',
description,
totalSeasons: 1,
totalEpisodes: 1,
genres: [],
creators: [],
posterUri: uri,
thumbnailUrl
};
// Use new mintWithMetadata method
const result = await this._ipnftWrapper.mintWithMetadata(to, uri, mediaMetadata, options);
return { tx: result.tx, tokenId: result.tokenId };
}
/**
* Get NFT details
* @param tokenId Token ID
* @returns NFT metadata
*/
async getNFTDetails(tokenId) {
await this._ipnftWrapper.init();
const tokenIdBN = ethers.BigNumber.from(tokenId);
const uri = await this._ipnftWrapper.tokenURI(tokenIdBN);
const owner = await this._ipnftWrapper.ownerOf(tokenIdBN);
const mediaInfo = await this._ipnftWrapper.getMediaInfo(tokenIdBN);
return {
tokenId: tokenIdBN,
uri,
owner,
...mediaInfo
};
}
/**
* Set media details for an NFT
* @param tokenId Token ID
* @param mediaData Media information
* @param options Transaction options
* @returns Transaction object
*/
async setMediaDetails(tokenId, mediaData, options) {
await this._ipnftWrapper.init();
return this._ipnftWrapper.setMediaInfo(tokenId, mediaData, options);
}
/**
* Check if a user is the owner of an NFT
* @param tokenId Token ID
* @param address User address
* @returns Whether the user is the owner
*/
async isOwner(tokenId, address) {
await this._ipnftWrapper.init();
return this._ipnftWrapper.isOwnerOf(address, tokenId);
}
/**
* Process connection update
*/
async onConnectionUpdated() {
// First update our own connection
await super.onConnectionUpdated();
// Update wrapper connection
this._ipnftWrapper.updateConnection(this._provider, this._signer);
await this._ipnftWrapper.init();
}
}