NEAR Provider API

Properties

near.isSender

true if the user has Sender installed.

Methods

near.requestSignIn()

/**
* request signin the contract, with the view and change methods provided, return the access key
* @param {*} contractId contract account id
* @param {*} methodNames the method names on the contract that should be allowed to be called. Pass null for no method names and '' or [] for any method names.
* @param {*} createNew if need create new access key, set createNew = true. Default is false
* @returns { accessKey } signed in access key
*/
near.requestSignIn({ contractId, methodNames, createNew = false }): Promise<Result>

Request sign in with the contract, given the needed view and change methods, return the access key (The response might be changed in future version).

const contractId = 'guest-book.testnet';
const methodNames = ['addMessage'];
const res = await window.near.requestSignIn({ contractId, methodNames });

near.signOut()

/**
* @param {*} contractId contract account id (options)
*/
near.signOut({ contractId }): Promise<Result>;

Sign out the access key from this account and then clean the signed in access key from the storage. Must need to pass the specific contractId if one dapp has multiple contractId.

near.isSignedIn()

/**
* @param {*} contractId contract account id (options)
*/
near.isSignedIn({ contractId }): boolean;

Check whether the current account has signed in. Must need to pass the specific contractId if one dapp has multiple contractId.

near.getAccountId()

near.getAccountId(): string;

The current selected NEAR account ID

[Work-In Progress] near.account()

near.account(): Account;

Return an instance of the account object in near-api-js . The usage can be found in the documentation here.

near.signAndSendTransaction()

near.signAndSendTransaction({ receiverId: string, actions: Action}): Response;

Send one single transaction

near.requestSignTransactions()

near.requestSignTransactions(options: SignAndSendTransactionOptions): void;

Send multiple transactions in batch

near.request()

near.request(method: string, params: Object): Object;

Use request to submit RPC requests to NEAR blockchain via Sender.

Events

signIn

An account has signed in

near.on("signIn", (() => {
  // TODO if account has signed in
});

signOut

The current account has signed out

near.on("signOut", (() => {
  // TODO if account has been signed out
});

accountChanged

Listen to the current account changed

near.on("accountChanged", ((changedAccountId) => {
  // TODO if account has changed
});

rpcChanged

Listen to the current RPC URL changed

near.on("rpcChanged", ((response) => {
  // TODO if rpc has changed
});

Last updated