Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mintbase-js/sdk

Package Overview
Dependencies
Maintainers
2
Versions
1314
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mintbase-js/sdk

Core functions for Mintbase JS SDK

  • 0.0.4-publish-on-push.0
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
increased by272.17%
Maintainers
2
Weekly downloads
 
Created
Source

[//]: # { "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:

  1. Sign with a browser wallet
  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.

{% 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 = {
  // the smart contract address for which we will call
  // most of the time, this will be supplied as an environment variable
  contractAddress: 'mytokencontract.mintbase1.near',

  // the smart contract method
  methodName: 'transfer',

  // the arguments supplied to the method
  args: { receiver_id: 'bob.near', token_id: '123' },

  // how much gas you would like to send
  // you will be refunded unused gas so MAX_GAS is always a safe bet
  gas: MAX_GAS,

  // most methods require the min amount of deposit (ONE_YOCTO) to be accepted.
  // in some cases deposit amount is the amount of currency to be transfer,
  deposit: ONE_YOCTO,
}

const makeSmartContractCall = async (): Promise<FinalExecutionOutcome> => {

  // to better understand signing options, read the auth module docs
  // to use an account directly, you have to implement this method
  // const account = await authenticateAccount('mynearaccount.near');

  // before the getWallet can be called, you will need to setup the components in the browser, it will throw othwerise
  const wallet = await getWallet();

  const sign: NearCallSigningOptions = {
    // account
    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 %}

FAQs

Package last updated on 17 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc