execute
Execute is our main wrapper for calls on mintbase.js
- It accepts a first Object as Argument that setup the batch call with the desired data.
- It accepts a N number of transactions.
execute
takes one Argument as NearExecuteOptions
and also one or more NearContractCallexport type NearExecuteOptions = {
// wallet
wallet: Wallet;
// contract address
account: Account;
// the page url that you want the user to be redirected after the success of the transaction. Must include full url ex:
// https://www.mintbase.xyz/success
callbackUrl?: string;
// Object that accepts desired arguments to be passed through the URL so you can get them to use in the success page
callbackArgs?: {
arg: string
arg2: number
};
}
- this argument can be set within mbjs.config ( globally ), thus if passed globally theres no need to be passed in the first obj argument. or in the execute method. it must be passed in full url. ex: "https://www.yourwebsite.xyz/success"
- Optional object that will be passed as an argument on the url, ex: "https://www.yourwebsite.xyz/success?signMeta=arg1:XYZ"
Example usage of list method in a hypothetical React component:
ListComponent.ts
1
import { useState } from 'react';
2
import { useWallet } from '@mintbase-js/react';
3
import { execute, list, ListArgs } from '@mintbase-js/sdk';
4
5
6
export const ListComponent = ({ contractAddress, marketAddress , tokenId, price }:ListArgs):JSX.Element => {
7
8
const { selector } = useWallet();
9
10
const handleList = async (): Promise<void> => {
11
const wallet = await selector.wallet();
12
13
14
const callBackArgs = {
15
autotransfer: true,
16
metadataId: id,
17
contractId: address,
18
}
19
20
const callback = {
21
args: callBackArgs,
22
type: TransactionSuccessEnum.SIMPLE_SALE_LIST
23
}
24
25
26
// 1. using callbackUrl + callbackArgs
27
28
const receipt = await execute(
29
{wallet, callbackUrl:'https://www.mintbase.xyz/success' , callbackArgs},
30
list({
31
contractAddress: nftContractId,
32
marketAddress: marketId,
33
tokenId: tokenId,
34
price: price
35
})
36
)
37
38
39
40
// 2. using callbackArgs, and set mbjs.config({callbackUrl: 'https://www.mintbase.xyz/success' }) on main app.tsx
41
42
const receipt = await execute(
43
{wallet, callbackArgs},
44
list({
45
contractAddress: nftContractId,
46
marketAddress: marketId,
47
tokenId: tokenId,
48
price: price
49
})
50
)
51
52
53
54
// 3.not using callbackArgs neither callbackUrl
55
// IF You decide to go by this approach:
56
// - Browser Wallets (Near Wallet, My Near Wallet): will redirect to the previous page with transactionsHash param
57
// - Injected Wallets (Meteor,Sender, etc) will return a receipt object
58
59
const receipt = await execute(
60
{wallet},
61
list({
62
contractAddress: nftContractId,
63
marketAddress: marketId,
64
tokenId: tokenId,
65
price: price
66
})
67
)
68
69
70
console.log(receipt, 'receipt')
71
72
return (
73
<div>
74
<button onClick={handleList}>
75
DeployContract with name= {name} and owner= {owner}
76
</button>
77
</div>
78
);
79
};
Last modified 9mo ago