Skip to content

Commit c4c56cd

Browse files
authored
Merge pull request #1 from niftykit-inc/presale-support
added presale support
2 parents 3ed2cbc + 09850b9 commit c4c56cd

34 files changed

+36
-9876
lines changed

src/DropKit.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import detectEthereumProvider from '@metamask/detect-provider'
22
import axios from 'axios'
33
import { ethers } from 'ethers'
4-
import {
5-
ADDRESS_CHECK_ENDPOINT,
6-
ADDRESS_CHECK_ENDPOINT_DEV,
7-
} from './config/endpoint'
4+
import { API_ENDPOINT, API_ENDPOINT_DEV } from './config/endpoint'
85
import DropKitCollectionABI from './contracts/DropKitCollection.json'
96
import DropKitCollectionV2ABI from './contracts/DropKitCollectionV2.json'
107
import DropKitCollectionV3ABI from './contracts/DropKitCollectionV3.json'
@@ -19,7 +16,9 @@ export default class DropKit {
1916
apiKey: string
2017
dev?: boolean
2118
address: string
19+
collectionId?: string
2220
contract: ethers.Contract | null
21+
walletAddress?: string
2322
version: number
2423

2524
constructor(key: string, isDev?: boolean) {
@@ -38,7 +37,7 @@ export default class DropKit {
3837
address: string
3938
}> {
4039
const { data } = await axios.get(
41-
this.dev ? ADDRESS_CHECK_ENDPOINT_DEV : ADDRESS_CHECK_ENDPOINT,
40+
`${this.dev ? API_ENDPOINT_DEV : API_ENDPOINT}/drops/address`,
4241
{
4342
headers: {
4443
'x-api-key': this.apiKey,
@@ -48,6 +47,7 @@ export default class DropKit {
4847

4948
if (data) {
5049
this.address = data.address
50+
this.collectionId = data.collectionId
5151
this.version = data.version
5252
const abi = abis[data.version || 1]
5353

@@ -64,6 +64,7 @@ export default class DropKit {
6464
const provider = new ethers.providers.Web3Provider(ethereum)
6565
const signerOrProvider = provider.getSigner()
6666

67+
this.walletAddress = await signerOrProvider.getAddress()
6768
this.contract = new ethers.Contract(data.address, abi, signerOrProvider)
6869
}
6970

@@ -123,18 +124,43 @@ export default class DropKit {
123124
return mintedNfts.toNumber()
124125
}
125126

126-
async mint(quantity: number): Promise<boolean> {
127+
async generateProof(): Promise<string> {
128+
const { data } = await axios.post(
129+
`${this.dev ? API_ENDPOINT_DEV : API_ENDPOINT}/drops/list/${
130+
this.collectionId
131+
}`,
132+
{
133+
wallet: this.walletAddress,
134+
}
135+
)
136+
137+
return data
138+
}
139+
140+
async mint(quantity: number): Promise<void> {
127141
if (!this.contract) {
128142
throw new Error('Initialization failed')
129143
}
130-
131144
const price = await this.price()
132145

146+
// Presale mint
147+
try {
148+
const proof = await this.generateProof()
149+
const results = await this.contract.presaleMint(quantity, proof, {
150+
value: ethers.utils.parseEther(price.toString()).mul(quantity),
151+
})
152+
await results.wait()
153+
154+
return
155+
} catch (err) {
156+
console.log(err)
157+
}
158+
133159
const results = await this.contract.mint(quantity, {
134160
value: ethers.utils.parseEther(price.toString()).mul(quantity),
135161
})
136162
await results.wait()
137163

138-
return true
164+
return
139165
}
140166
}

src/config/endpoint.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
export const ADDRESS_CHECK_ENDPOINT_DEV =
2-
'https://niftykit-dev.herokuapp.com/api/drops/address'
3-
4-
export const ADDRESS_CHECK_ENDPOINT =
5-
'https://app.niftykit.com/api/drops/address'
1+
export const API_ENDPOINT_DEV = 'https://niftykit-dev.herokuapp.com/api'
2+
export const API_ENDPOINT = 'https://app.niftykit.com/api'

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import DropKit from './DropKit'
22

33
export default DropKit
4-

0 commit comments

Comments
 (0)