从 Near Web Wallet 迁移
虽然我们强烈建议使用正式 API 来让你的应用与 OneKey 钱包交互,但我们仍然提供了一些与 Near Web Wallet 非常相似的旧版 API,使你更容易从 Near Web Wallet 迁移现有代码。
import * as nearAPI from "near-api-js";
const config = {
networkId: 'mainnet',
nodeUrl: 'https://rpc.mainnet.near.org',
// networkId: 'testnet',
// nodeUrl: 'https://rpc.testnet.near.org',
headers: {},
keyStore: new nearAPI.keyStores.BrowserLocalStorageKeyStore(),
}
const near = new nearAPI.Near(config);
const connection = near.connection;
const provider = new OneKeyNearProvider({
connection,
networkId: 'mainnet', // `mainnet` 或 `testnet`
// 登录或签署交易后重新加载页面,类似于 web wallet 回调 URL 的工作方式
enablePageReload: true,
});
provider.requestSignIn({
successUrl,
failureUrl,
contractId?,
});
provider.getAccountId();
provider.isSignedIn();
provider.signOut();
provider.requestSignTransactions({
transactions: [],
callbackUrl,
meta?,
});
provider.account().signAndSendTransaction({
receiverId,
actions: [],
walletCallbackUrl,
walletMeta?,
});
注意: 旧版 API 没有经过完整测试和全面的用例覆盖。请尽可能使用正式 API。
Last updated on