-
Notifications
You must be signed in to change notification settings - Fork 0
/
use-handle-burn.ts
60 lines (50 loc) · 1.36 KB
/
use-handle-burn.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { burnV1 } from "@metaplex-foundation/mpl-core";
import {
setComputeUnitLimit,
setComputeUnitPrice,
} from "@metaplex-foundation/mpl-toolbox";
import {
type RpcConfirmTransactionResult,
type Umi,
publicKey,
transactionBuilder,
} from "@metaplex-foundation/umi";
import { useMutation } from "@tanstack/react-query";
interface Input {
umi: Umi;
assetPublicKey: string;
}
interface Output {
signature: Uint8Array;
result: RpcConfirmTransactionResult;
}
export const useHandleBurn = () => {
const mutation = useMutation<Output, Error, Input>({
mutationFn: async ({ umi, assetPublicKey }: Input): Promise<Output> => {
console.log(`Minting NFT for ${assetPublicKey}`);
const asset = publicKey(assetPublicKey);
let transactions = transactionBuilder();
transactions = transactions.add(
burnV1(umi, {
asset: asset,
}),
);
transactions = transactions.prepend(
setComputeUnitPrice(umi, { microLamports: 1_000_000 }),
);
transactions = transactions.prepend(
setComputeUnitLimit(umi, { units: 800_000 }),
);
const result = await transactions.sendAndConfirm(umi, {
send: {
commitment: "finalized",
},
confirm: {
commitment: "finalized",
},
});
return result;
},
});
return mutation;
};