forked from stevyhacker/rmrk-minimal-evm-ui
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmint-nft.ts
26 lines (25 loc) · 979 Bytes
/
mint-nft.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { NewTransaction } from '@rainbow-me/rainbowkit/dist/transactions/transactionStore';
import { Contract, ethers, Signer } from 'ethers';
import abis from '../../abis/abis';
interface IProps {
signer?: ethers.Signer | null;
contractAddress: string;
addRecentTransaction: (transaction: NewTransaction) => void;
}
export const mintNft = async ({ signer, contractAddress, addRecentTransaction }: IProps) => {
if (signer instanceof Signer && ethers.utils.isAddress(contractAddress)) {
const caller = await signer.getAddress();
const multiResourceContract = new Contract(contractAddress, abis.multiResourceAbi, signer);
const value = await multiResourceContract.pricePerMint();
const options = {
value,
};
const tx = await multiResourceContract.connect(signer).mint(caller, 1, options);
await tx.wait();
addRecentTransaction({
hash: tx.hash,
description: 'Minting a new RMRK NFT',
confirmations: 1,
});
}
};