Links

@mintbase-js/sdk

Core Features

The core @mintbase-js/sdk is a set of convenience wrappers around invocation of Mintbase smart contract methods.
It also exposes a low-level isomorphic execute method that can be passed raw NearContractCall information.

Calling Smart Contract Methods

In order to invoke a smart contract method, the transaction has to be signed using a public/private key pair.
There are two options, both provided from the @mintbase-js/auth module:
  1. 1.
    Sign with a browser wallet​
  2. 2.
    Sign with an authenticated account.

Using API Methods

The easiest way to call mintbase token and market contracts are with the convenience methods.
Details such as the method name, arguments, gas supplied, deposits and some other less than convenient aspects of blockchain development will be abstracted away for you, or at least well documented in each example.
This is a work in progress, please reach out to us on Telegram for support.

Using execute

The excecute method can be used without api helpers, however you will need to specify all NearContractCall properties.
The method accepts any number of contract calls as arguments after the signingOptions argument in first position:
execute(
signingOptions: NearCallSigningOptions
calls: NearContractCall[],
): Promise<providers.FinalExecutionOutcome | providers.FinalExecutionOutcome[]>
Here is an example using the execute function call:

NearContractCall

This type specifies properties of a contract calls. Each of the API convenience methods returns this object type, however you are welcome to create this object manually:
executeContractMethod.ts
1
import { execute, MAX_GAS, ONE_YOCTO, transfer } from '@mintbase-js/sdk';
2
import { getWallet } from '@mintbase-js/auth';
3
import type {
4
NearContractCall,
5
NearCallSigningOptions,
6
FinalExecutionOutcome
7
} from '@mintbase-js/sdk';
8
​
9
// create a contact call from scratch
10
​
11
const myCustomContractCall: NearContractCall<ExecuteArgsResponse>= {
12
// who should be signing the transaction
13
signerId: 'you.near',
14
​
15
// contract address
16
contractAddress: 'my.contract.address.near',
17
​
18
// the contract method name
19
methodName: 'my_contract_method',
20
​
21
// specify arguments for call_method
22
args: { },
23
​
24
// amount of gas to attach to the transactions
25
gas: MAX_GAS,
26
​
27
// the deposit to be sent along with the transaction
28
deposit: ONE_YOCTO,
29
};
30
​
31
​
32
// create a `NearContractCall` object using a helper method:
33
// note how this takes care of creating all the above properties
34
const transferCall = transfer({
35
nftContractId: 'mytokencontract.mintbase1.near',
36
transfers: [{
37
receiverId: 'bob.near',
38
tokenId: '123',
39
}],
40
})
41
​
42
const makeSmartContractCall = async (): Promise<FinalExecutionOutcome> => {
43
​
44
// to better understand signing options, read the auth module docs
45
// to use an account directly, you have to implement this method
46
// const account = await authenticateAccount('mynearaccount.near');
47
​
48
// before the getWallet can be called, you will need to setup context in the browser, it will throw otherwise
49
const wallet = await getWallet();
50
​
51
const options: NearExecuteOptions = {
52
// account
53
wallet,
54
callbackUrl: 'https://www.yourwebsite.xyz/success'
55
}
56
​
57
// call sign with options,
58
return await execute(options, myCustomContractCall, transferCall);
59
}
60
​
61
makeSmartContractCall()
62
.then((res: FinalExecutionOutcome) => console.log('got transaction result:', res))
63
.catch((err) => console.error('things went wrong', err));
64
​

Batching Transactions

When calling more than one method with execute the returned value will be a promise with an array of results Promise<FinalExecutionOutcome[]> To use execute with batching all you need to do is supply as many calls as intended through arguments execute(sign, mint, transfer, mint, burn ) in this manner executions will happen in order.

Composition of Calls

Some api wrappers might be a composition of various contract calls that are often executed in succession like depositStorage+ list or revoke+ unlist. The only difference is that in this case although you are technically calling execute with one method execute(sign, delist) you will receive 2 outcome objects in the resulting promise.
If you would like to create a composition yourself you can do so like this.
const mintCall = mint({
nftContractId: 'placeholder',
ownerId: 'placeholder',
reference: 'placeholder',
});
​
const composed: NearContractCall = [mintCall, mintCall] as ContractCall[];
​
const result = execute(sign, composed) as FinalExecutionOutcome[];
​

Further

Should you encounter this known issue Class PublicKey is missing in schema: publicKey make sure you are not importing modules directly from near-api-js, import them from @mintbase-js/sdk instead to avoid the duplicate import.