0.0.14 • Published 8 months ago
basemint-sdk v0.0.14
BaseMint SDK
A TypeScript SDK for interacting with the BaseMint Protocol - a decentralized NFT collection deployment and management platform.
Overview
BaseMint SDK provides a simple and type-safe way to interact with the BaseMint Protocol. It enables:
Collection Management
- Deploy new ERC721 and ERC1155 collections
- Customize collection parameters (name, symbol, supply, pricing)
- Set minting timeframes and limits
- Manage collection metadata and URIs
Secure Deployment
- Two-step signature verification process
- Creator signature validation
- Deployer signature validation
- Collection address prediction
Token Operations
- Mint ERC721 and ERC1155 tokens
- Automatic price calculation
- Built-in parameter validation
- Gas-efficient transactions
Reward Distribution
- Track creator rewards
- Distribute accumulated rewards
- Monitor reward distribution events
- Query historical distributions
Developer Experience
- Full TypeScript support
- Comprehensive type definitions
- Built-in validation
- Error handling
- Event tracking
- Frontend-ready with wallet integration
Technical Features
- Modern viem-based architecture
- Gas-optimized contract interactions
- Automatic ABI handling
- Built-in type safety
Installation
npm install @basemint/sdk
Usage
Initialize Clients
First, set up the blockchain clients. In a frontend environment, the wallet client comes from the user's wallet connection.
import { createPublicClient, http, WalletClient } from 'viem'
import { sepolia } from 'viem/chains'
// Public client for reading blockchain data
const publicClient = createPublicClient({
chain: sepolia,
transport: http('YOUR_SEPOLIA_RPC_URL')
})
// Wallet client comes from user's wallet connection (e.g., MetaMask)
declare const walletClient: WalletClient
Deploy Collection
Deploy a new NFT collection with signature verification:
import {
BaseMintFactory,
FACTORY_ADDRESS,
generateCreatorSignature,
generateDeployerSignature,
CollectionMetadata
} from '@basemint/sdk'
import { parseEther } from 'viem'
// Initialize factory
const factory = new BaseMintFactory(
publicClient,
FACTORY_ADDRESS[sepolia.id],
walletClient
)
// Prepare collection metadata
const metadata: CollectionMetadata = {
name: 'My Collection',
symbol: 'MC',
baseURI: 'ipfs://YOUR_CID/',
creator: walletClient?.account?.address,
maxSupply: 1000n,
mintPrice: parseEther('0.1'),
startTime: BigInt(Math.floor(Date.now() / 1000) + 3600),
endTime: BigInt(Math.floor(Date.now() / 1000) + 86400)
}
// Generate signatures
const creatorSignature = await generateCreatorSignature(
walletClient,
publicClient,
FACTORY_ADDRESS[sepolia.id],
metadata
)
const deployerSignature = await generateDeployerSignature(
walletClient,
publicClient,
FACTORY_ADDRESS[sepolia.id],
metadata,
creatorSignature
)
// Deploy collection
const tx = await factory.deployCollection(
metadata,
creatorSignature,
deployerSignature,
false // isERC1155: false for ERC721
)
// Wait for deployment
const receipt = await publicClient.waitForTransactionReceipt({ hash: tx })
console.log('Collection deployed at:', receipt.contractAddress)
Mint Tokens
Mint tokens from a deployed collection:
import { BaseMintCollection, calculateMintCost } from '@basemint/sdk'
// Initialize collection
const collection = new BaseMintCollection(
publicClient,
'0x0000000000000000000000000000000000000000', // collection address
false, // isERC1155: false
walletClient
)
// Get collection info
const info = await collection.getCollectionInfo()
console.log('Collection Info:', info)
// Calculate mint cost
const amount = 1n
const mintCost = await calculateMintCost(collection, amount)
// Mint token
const tx = await collection.mint(amount, undefined, mintCost)
console.log('Mint transaction:', tx)
// Wait for mint
const receipt = await publicClient.waitForTransactionReceipt({ hash: tx })
console.log('Token minted:', receipt)
Manage Rewards
Handle creator rewards distribution:
import {
BaseMintEscrow,
ESCROW_ADDRESS,
getRewardDistributionEvents
} from '@basemint/sdk'
import { formatEther } from 'viem'
// Initialize escrow contract
const escrow = new BaseMintEscrow(
publicClient,
ESCROW_ADDRESS[sepolia.id],
walletClient
)
// Get collection rewards
const collectionAddress = '0x0000000000000000000000000000000000000000' // Your collection address
const rewards = await escrow.getPendingRewards(collectionAddress)
console.log('Available rewards:', formatEther(rewards), 'ETH')
// Get distribution events
const latestBlock = await publicClient.getBlockNumber()
const events = await getRewardDistributionEvents(
publicClient,
ESCROW_ADDRESS[sepolia.id],
latestBlock - 1000n, // Last 1000 blocks
latestBlock
)
console.log('Recent distributions:', events)
Signature Verification
Verify signatures and predict collection addresses:
import { BaseMintFactory, FACTORY_ADDRESS } from '@basemint/sdk'
// Verify signatures and predict collection address
const predictedAddress = await factory.predictCollectionAddress(
metadata,
creatorSignature,
deployerSignature,
false // isERC1155: false for ERC721
)
// Verify signatures
const verifiedAddress = await factory.checkSignature(
metadata,
creatorSignature,
deployerSignature
)
Type Definitions
Collection Metadata
import { CollectionMetadata } from '@basemint/sdk'
interface CollectionMetadata {
name: string
symbol: string
baseURI: string
creator: Address
maxSupply: bigint
mintPrice: bigint
startTime: bigint
endTime: bigint
}
Mint Parameters
import { MintParams } from '@basemint/sdk'
interface MintParams {
amount: bigint
value: bigint
tokenId?: bigint // Required for ERC1155
}
Error Handling
The SDK includes built-in validation and error handling:
import { validateDeploymentConfig, validateMintParams } from '@basemint/sdk'
// Validate deployment config
const error = validateDeploymentConfig(metadata)
if (error) {
console.error('Invalid deployment config:', error)
}
// Validate mint parameters
const mintError = validateMintParams(params, isERC1155)
if (mintError) {
console.error('Invalid mint parameters:', mintError)
}
Development
# Install dependencies
npm install
# Build
npm run build
# Test
npm test
# Lint
npm run lint
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT