@@ -5,17 +5,22 @@ import {
55 ADDRESS_CHECK_ENDPOINT ,
66 ADDRESS_CHECK_ENDPOINT_DEV ,
77} from './config/endpoint'
8- import {
9- DropKitCollection ,
10- // eslint-disable-next-line camelcase
11- DropKitCollection__factory ,
12- } from './typechain-types'
8+ import DropKitCollectionABI from './contracts/DropKitCollection.json'
9+ import DropKitCollectionV2ABI from './contracts/DropKitCollectionV2.json'
10+ import DropKitCollectionV3ABI from './contracts/DropKitCollectionV3.json'
11+
12+ const abis : Record < number , any > = {
13+ 2 : DropKitCollectionABI . abi ,
14+ 3 : DropKitCollectionV2ABI . abi ,
15+ 4 : DropKitCollectionV3ABI . abi ,
16+ }
1317
1418export default class DropKit {
1519 apiKey : string
1620 dev ?: boolean
1721 address : string
18- contract : DropKitCollection | null
22+ contract : ethers . Contract | null
23+ version : number
1924
2025 constructor ( key : string , isDev ?: boolean ) {
2126 if ( ! key ) {
@@ -26,6 +31,7 @@ export default class DropKit {
2631 this . dev = isDev
2732 this . address = ''
2833 this . contract = null
34+ this . version = 0
2935 }
3036
3137 async init ( ) : Promise < {
@@ -42,6 +48,8 @@ export default class DropKit {
4248
4349 if ( data ) {
4450 this . address = data . address
51+ this . version = data . version
52+ const abi = abis [ data . version || 1 ]
4553
4654 // const ethereum = (window as any).ethereum!
4755 const ethereum = ( await detectEthereumProvider ( ) ) as any
@@ -56,10 +64,7 @@ export default class DropKit {
5664 const provider = new ethers . providers . Web3Provider ( ethereum )
5765 const signerOrProvider = provider . getSigner ( )
5866
59- this . contract = DropKitCollection__factory . connect (
60- data . address ,
61- signerOrProvider
62- )
67+ this . contract = new ethers . Contract ( data . address , abi , signerOrProvider )
6368 }
6469
6570 return data . address
@@ -76,7 +81,10 @@ export default class DropKit {
7681 throw new Error ( 'Initialization failed' )
7782 }
7883
79- const dropPrice = await this . contract . price ( )
84+ const dropPrice =
85+ this . version <= 3
86+ ? await this . contract . _price ( )
87+ : await this . contract . price ( )
8088 return Number ( ethers . utils . formatEther ( dropPrice ) )
8189 }
8290
@@ -85,7 +93,11 @@ export default class DropKit {
8593 throw new Error ( 'Initialization failed' )
8694 }
8795
88- const maxMint = await this . contract . maxPerMint ( )
96+ const maxMint =
97+ this . version <= 3
98+ ? await this . contract . _maxPerMint ( )
99+ : await this . contract . maxPerMint ( )
100+
89101 return maxMint . toNumber ( )
90102 }
91103
@@ -94,7 +106,11 @@ export default class DropKit {
94106 throw new Error ( 'Initialization failed' )
95107 }
96108
97- const maxWallet = await this . contract . maxPerWallet ( )
109+ const maxWallet =
110+ this . version <= 3
111+ ? await this . contract . _maxPerWallet ( )
112+ : await this . contract . maxPerWallet ( )
113+
98114 return maxWallet . toNumber ( )
99115 }
100116
0 commit comments