MTCoreCard.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {
  2. JsonRpcSigner,
  3. ContractTransactionResponse,
  4. ContractTransactionReceipt,
  5. } from 'ethers'
  6. import { CONTRACT_CORECARD } from '../../../constants'
  7. import Erc721TokenContract from './erc721'
  8. import ABI from './MTCoreCardABI.json'
  9. export type MTCoreCardLevel = 0 | 1 | 2 | 3 | 4
  10. export default class MTCoreCardContract extends Erc721TokenContract {
  11. constructor(provider: JsonRpcSigner) {
  12. super(CONTRACT_CORECARD, provider)
  13. this.ABI = ABI
  14. }
  15. async mint(
  16. level: MTCoreCardLevel,
  17. price: string,
  18. address?: string
  19. ): Promise<ContractTransactionReceipt> {
  20. const useAddress = address ?? (await this.getCallerAddress())
  21. const contract = this.getInstance()
  22. const tx: ContractTransactionResponse = await contract.mint(
  23. useAddress,
  24. level,
  25. {
  26. value: price,
  27. }
  28. )
  29. const txwait = await tx.wait()
  30. if (!txwait) {
  31. throw new Error('Transaction failed')
  32. }
  33. return txwait
  34. }
  35. async getMintPrice(level: MTCoreCardLevel): Promise<string> {
  36. const contract = this.getInstance()
  37. const bn = await contract.getMintPrice(level)
  38. return bn.toString()
  39. }
  40. async getAllMintPrice(): Promise<[string, string, string, string, string]> {
  41. const lv0 = await this.getMintPrice(0)
  42. const lv1 = await this.getMintPrice(1)
  43. const lv2 = await this.getMintPrice(2)
  44. const lv3 = await this.getMintPrice(3)
  45. const lv4 = await this.getMintPrice(4)
  46. return [lv0, lv1, lv2, lv3, lv4]
  47. }
  48. }