• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Mintbase / mintbase-js / 3641052425

pending completion
3641052425

push

github

Sérgio
merge

173 of 224 branches covered (77.23%)

Branch coverage included in aggregate %.

417 of 444 relevant lines covered (93.92%)

3.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.82
/packages/sdk/src/mint/mint.ts
1
/* eslint-disable @typescript-eslint/camelcase */
2
import { GAS, ONE_YOCTO, TOKEN_METHOD_NAMES } from '../constants';
1✔
3
import { NearContractCall } from '../execute';
4

5

6
export type MintArgs =  {
7
  nftContractId: string;
8
  reference: string;
9
  ownerId: string;
10
  options?: MintOptions;
11
};
12

13
export type MintOptions = {
14
    splits?: Splits;
15
    amount?: number;
16
    royaltyPercentage?: number;
17
}
18

19
export type Splits = Record<string, number>;
20

21
/**
22
 * Mint a token given via reference json on a given contract with a specified owner, amount of copies as well and royalties can be specified via options
23
 * @param mintArguments {@link MintArgs}
24
 * @returns contract call to be passed to @mintbase-js/sdk execute method
25
 */
26
export const mint = (
1✔
27
  args: MintArgs,
28
): NearContractCall => {
29
  const { nftContractId, reference, ownerId, options = {}  } = args;
5✔
30

31
  const { splits, amount, royaltyPercentage } = options;
5✔
32
  
33
  if (splits) {
5✔
34
    //0.5 -> 5000
35
    adjustSplitsForContract(splits);
4✔
36
  }
37

38
  if (splits && Object.keys(splits).length > 50) {
2!
39
    throw ('Splits cannnot have more than 50 entries');
×
40
  }
41

42
  if (splits && Object.keys(splits).length < 2) {
2!
43
    throw ('There must be at least 2 accounts in splits');
×
44
  }
45

46
  if (amount && amount > 99) {
2!
47
    throw ('It is not possible to mint more than 99 copies of this token using this method');
×
48
  }
49

50
  if (royaltyPercentage && royaltyPercentage < 0 || royaltyPercentage > 0.5) {
2!
51
    throw ('Invalid royalty percentage');
×
52
  }
53
  
54
  return {
2✔
55
    contractAddress: nftContractId,
56
    args: {
57
      owner_id: ownerId,
58
      metadata: {
59
        reference: reference,
60
      },
61
      num_to_mint: amount || 1,
3✔
62
      // 10000 = 100%
63
      royalty_args: !splits ? null : { split_between: splits, percentage: royaltyPercentage * 10000 }, 
2✔
64
      split_owners: splits || null,
3✔
65
    },
66
    methodName: TOKEN_METHOD_NAMES.MINT,
67
    gas: GAS,
68
    deposit: ONE_YOCTO,
69
  };
70
};
71

72
function adjustSplitsForContract(splits: Record<string, number> ): void {
73
  let counter = 0;
4✔
74
  Object.keys(splits).forEach(key => {
4✔
75
    counter += splits[key];
56✔
76
    console.log(counter);
56✔
77
    splits[key] *= 10000;
56✔
78
  });
79
  if (counter != 1) {
4✔
80
    throw ('Splits percentages must add up to 1');
3✔
81
  }
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc