[//]: # { "title": "@mintbase-js/sdk", "order": 0 }
SDK Core Javascript Modules
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:
- Sign with a browser wallet
- 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.
{% hint style="warning" %}
This is a work in progress, please reach out to us on Telegram for support.
{% endhint %}
Check back soon for details. Individual methods and documentation will start to be available as we implement in the gitbook documentation menu.
Using execute
You are always free to use the core execute method without the API methods, which will allow you to specify all options of the contract call.
The method will accept a single NearContractCall
object or an array of calls and determine how batch based on NearCallSigningOptions
(browser wallet, or near-api-js Account).
execute(
calls: NearContractCall | NearContractCall[],
signingOptions: NearCallSigningOptions
): Promise<void | providers.FinalExecutionOutcome>
Here is an example using the raw function call
NearContractCall
The NearContractCall
type specifies the properties that our contract calls must specify:
{% code title="executeContractMethod.ts" overflow="wrap" lineNumbers="true" %}
import { execute, MAX_GAS, ONE_YOCTO } from '@mintbase-js/sdk';
import { getWallet } from '@mintbase-js/auth';
import type {
NearContractCall,
NearCallSigningOptions,
FinalExecutionOutcome
} from '@mintbase-js/sdk';
const call: NearContractCall = {
contractAddress: 'mytokencontract.mintbase1.near',
methodName: 'transfer',
args: { receiver_id: 'bob.near', token_id: '123' },
gas: MAX_GAS,
deposit: ONE_YOCTO,
}
const makeSmartContractCall = async (): Promise<FinalExecutionOutcome> => {
const wallet = await getWallet();
const sign: NearCallSigningOptions = {
wallet,
}
return await execute(call, sign);
}
makeSmartContractCall()
.then((res: FinalExecutionOutcome) => console.log('got transaction result:', res))
.catch((err) => console.error('things went wrong', err));
{% endcode %}
Batching Transactions
The reason for the optional Promise<void>
return type in the execute method, is that batch methods in some [near/wallet-selector] implementations do not return transactions execution outcomes.
Further
{% hint style="warning" %}
Should you encounter this known issue make sure you are not importing modules directly from near-api-js
, import them from @mintbase-js/sdk
instead to avoid the duplicate import.
{% endhint %}