@@ -5,17 +5,24 @@ import {
55 TokenMetadataInputSchema ,
66} from "../types/contracts" ;
77import {
8- NFTDropContractSchema ,
8+ NFTDropConditionsOutputSchema ,
99 NFTDropMetadataInput ,
1010} from "../types/contracts/nft-drop" ;
1111import { enforceCreator } from "./helpers/creators-helper" ;
12- import { findMetadataPda , Metaplex , token } from "@metaplex-foundation/js" ;
12+ import {
13+ findMetadataPda ,
14+ Metaplex ,
15+ sol ,
16+ toBigNumber ,
17+ token ,
18+ } from "@metaplex-foundation/js" ;
1319import {
1420 createCreateMetadataAccountV2Instruction ,
1521 DataV2 ,
1622} from "@metaplex-foundation/mpl-token-metadata" ;
17- import { Keypair , PublicKey } from "@solana/web3.js" ;
23+ import { Keypair } from "@solana/web3.js" ;
1824import { IStorage } from "@thirdweb-dev/storage" ;
25+ import BN from "bn.js" ;
1926
2027export class Deployer {
2128 private metaplex : Metaplex ;
@@ -94,23 +101,52 @@ export class Deployer {
94101 }
95102
96103 async createNftDrop ( metadata : NFTDropMetadataInput ) : Promise < string > {
97- const parsed = NFTDropContractSchema . parse ( metadata ) ;
104+ const collectionInfo = NFTCollectionMetadataInputSchema . parse ( metadata ) ;
105+ const candyMachineInfo = NFTDropConditionsOutputSchema . parse ( metadata ) ;
106+ const uri = await this . storage . uploadMetadata ( collectionInfo ) ;
98107
99- // TODO make it a single tx
100- const collection = await this . createNftCollection ( metadata ) ;
108+ const collectionMint = Keypair . generate ( ) ;
109+ const collectionTx = await this . metaplex
110+ . nfts ( )
111+ . builders ( )
112+ . create ( {
113+ useNewMint : collectionMint ,
114+ name : collectionInfo . name ,
115+ symbol : collectionInfo . symbol ,
116+ sellerFeeBasisPoints : 0 ,
117+ uri,
118+ isCollection : true ,
119+ creators : enforceCreator (
120+ collectionInfo . creators ,
121+ this . metaplex . identity ( ) . publicKey ,
122+ ) ,
123+ } ) ;
101124
102- const { candyMachine : nftDrop } = await this . metaplex
125+ const candyMachineKeypair = Keypair . generate ( ) ;
126+ const candyMachineTx = await this . metaplex
103127 . candyMachines ( )
128+ . builders ( )
104129 . create ( {
105- ...parsed ,
106- collection : new PublicKey ( collection ) ,
130+ ...candyMachineInfo ,
131+ price : candyMachineInfo . price || sol ( 0 ) ,
132+ sellerFeeBasisPoints : candyMachineInfo . sellerFeeBasisPoints || 0 ,
133+ itemsAvailable : candyMachineInfo . itemsAvailable || toBigNumber ( 0 ) ,
134+ candyMachine : candyMachineKeypair ,
135+ collection : collectionMint . publicKey ,
107136 creators : enforceCreator (
108- parsed . creators ,
137+ collectionInfo . creators ,
109138 this . metaplex . identity ( ) . publicKey ,
110139 ) ,
111- } )
112- . run ( ) ;
140+ } ) ;
141+
142+ const result = await collectionTx
143+ . add ( candyMachineTx )
144+ . sendAndConfirm ( this . metaplex ) ;
145+
146+ if ( ! result . response . signature ) {
147+ throw new Error ( "Transaction failed" ) ;
148+ }
113149
114- return nftDrop . address . toBase58 ( ) ;
150+ return candyMachineKeypair . publicKey . toBase58 ( ) ;
115151 }
116152}
0 commit comments