forked from stevyhacker/rmrk-minimal-evm-ui
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeploy-contract.ts
46 lines (41 loc) · 1.34 KB
/
deploy-contract.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { NewTransaction } from '@rainbow-me/rainbowkit/dist/transactions/transactionStore';
import { BigNumber, Contract, ContractTransaction, ethers, Signer } from 'ethers';
import { RMRKMultiResourceFactoryContractAddress } from '../../constants';
interface IProps {
signer?: ethers.Signer | null;
registryContract: Contract;
tokenContract: Contract;
callFactory: () => Promise<ContractTransaction>;
addRecentTransaction: (transaction: NewTransaction) => void;
}
export async function deployContract({
signer,
registryContract,
tokenContract,
callFactory,
addRecentTransaction,
}: IProps) {
if (signer instanceof Signer) {
const caller = await signer.getAddress();
const deposit: BigNumber = await registryContract.getCollectionListingFee();
const allowance: BigNumber = await tokenContract.allowance(
caller,
RMRKMultiResourceFactoryContractAddress,
);
if (allowance.lt(deposit)) {
const approveTransactionResponse = await tokenContract.approve(
RMRKMultiResourceFactoryContractAddress,
deposit,
);
await approveTransactionResponse.wait();
}
const tx = await callFactory();
addRecentTransaction({
hash: tx.hash,
description: 'Deploying a new RMRK NFT contract',
confirmations: 1,
});
const receipt = await tx.wait();
return receipt;
}
}