UNPKG

@paulstinchcombe/kami721c-sdk

Version:

SDK for interacting with KAMI721C NFT contracts

97 lines (96 loc) 4.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.KAMI721CFactory = void 0; const ethers_1 = require("ethers"); // import KAMI721CABI from '../abis/KAMI721C.json'; const KAMI721C_1 = require("../contracts/KAMI721C"); const KAMI721C_json_1 = __importDefault(require("../abis/KAMI721C/KAMI721C.json")); /** * Factory class for deploying KAMI721C contracts */ class KAMI721CFactory { /** * Creates a new instance of the KAMI721C factory * @param signer A signer with deployment permissions */ constructor(signer) { // Create factory with ABI and bytecode from the compiled contract this.factory = new ethers_1.ContractFactory(KAMI721C_json_1.default.abi, KAMI721C_json_1.default.bytecode, // The bytecode is already a string in the JSON signer); } /** * Deploy a new KAMI721C contract * @param usdcAddress The address of the USDC token contract * @param name The name of the NFT collection * @param symbol The symbol of the NFT collection * @param baseURI The base URI for token metadata * @param initialMintPrice The initial mint price in USDC (with 6 decimals) * @param platformAddress The address that will receive platform commissions * @param platformCommissionPercentage The platform commission percentage in basis points (e.g., 500 = 5%) * @returns The deployed contract instance */ async deploy(usdcAddress, name, symbol, baseURI, initialMintPrice = 1000000n, // Default 1 USDC (6 decimals) platformAddress, platformCommissionPercentage = 500 // Default 5% ) { // If platform address not provided, use the deployer's address if (!platformAddress) { // Get the signer's address if ('getAddress' in this.factory.runner) { platformAddress = await this.factory.runner.getAddress(); } else { throw new Error('Platform address is required when deployer address cannot be determined'); } } console.log('Deploying contract with parameters:', { usdcAddress, name, symbol, baseURI, initialMintPrice, platformAddress, platformCommissionPercentage, }); try { console.log('Creating deployment transaction...'); // Add gas limit to avoid out of gas errors const contract = await this.factory.deploy(usdcAddress, name, symbol, baseURI, initialMintPrice, platformAddress, platformCommissionPercentage, { gasLimit: 5000000 } // Set a reasonable gas limit ); console.log('Waiting for deployment transaction to be mined...'); await contract.waitForDeployment(); const address = await contract.getAddress(); console.log('Contract deployed at address:', address); // Verify the contract was deployed successfully console.log('Verifying contract deployment...'); const provider = contract.runner?.provider; if (!provider) { throw new Error('Contract deployment failed - no provider available'); } const code = await provider.getCode(address); if (!code || code === '0x') { throw new Error('Contract deployment failed - no code at contract address'); } console.log('Contract code verified successfully'); const runner = contract.runner; if (!runner) { throw new Error('Contract deployment failed - no runner available'); } return new KAMI721C_1.KAMI721C(runner, address); } catch (error) { // Log more detailed error information console.error('Deployment failed:', { error: error.message, reason: error.reason, code: error.code, data: error.data, transaction: error.transaction, }); throw error; } } } exports.KAMI721CFactory = KAMI721CFactory;