Near
在 Bitget Wallet App 及安装 Chrome Extension 的 Chrome 浏览器中运行 DApp 时,可获得全局对象 window.bitkeep.near
并进行后续的 API 调用。
js
const provider = window.bitkeep.near;
const provider = window.bitkeep.near;
注入对象的属性和方法
getAccountId
- () => string:获取账户 IDgetPublicKey
- () => string:获取公钥requestSignIn
- (params) => Promise:请求签名isSignedIn
- () => Boolean:是否已签入signOut
- () => Promise:签出signAndSendTransaction
- (param) => Promise:签名并发送verifyOwner
- (message, accountId) => Promise:验证 OwnerrequestSignTransactions
- ({ transactions }) => Promise:请求签名
请求登录合约
给出所需的查看和更改方法,返回访问密钥(响应可能在未来版本中更改)。
js
/**
* 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
*/
provider.requestSignIn({ contractId, methodNames, createNew = false }): Promise<Result>
/**
* 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
*/
provider.requestSignIn({ contractId, methodNames, createNew = false }): Promise<Result>
js
const contractId = "guest-book.testnet";
const methodNames = ["addMessage"];
const res = await provider.requestSignIn({ contractId, methodNames });
const contractId = "guest-book.testnet";
const methodNames = ["addMessage"];
const res = await provider.requestSignIn({ contractId, methodNames });
注销访问密钥
从此帐户注销访问密钥,然后从存储中清除已登录的访问密钥。如果一个 dapp 有多个 contractId,则必须需要传递具体的 contractId。
js
/**
* @param {*} contractId contract account id (options)
*/
near.signOut({ contractId }): Promise<Result>;
/**
* @param {*} contractId contract account id (options)
*/
near.signOut({ contractId }): Promise<Result>;
检查当前账户是否已登录
如果一个 dapp 有多个 contractId,则需要传入具体的 contractId。
js
/**
* @param {*} contractId contract account id (options)
*/
near.isSignedIn({ contractId }): boolean;
/**
* @param {*} contractId contract account id (options)
*/
near.isSignedIn({ contractId }): boolean;
获取公钥
js
/**
* @param {*} contractId contract account id (options)
*/
await near.getPublicKey(): string;
/**
* @param {*} contractId contract account id (options)
*/
await near.getPublicKey(): string;
验证所属人
js
await near.verifyOwner(message, accountId, networdkId): boolean;
await near.verifyOwner(message, accountId, networdkId): boolean;
签署并发送一笔交易
js
near.signAndSendTransaction({ receiverId: string, actions: Action}): Response;
near.signAndSendTransaction({ receiverId: string, actions: Action}): Response;
签署并发送多笔交易 RPC 请求
js
near.signAndSendTransactions({ receiverId: string, actions: Action}): Response;
near.signAndSendTransactions({ receiverId: string, actions: Action}): Response;