/*** Initial the wallet. If current account has already sign in this contract, init() will auto signin* @param {*} contractId contract account id* @returns { accessKey } accessKey is empty string("") if has not request sign in before.*/init({ contractId })
/*** * @returns current account id*/getAccountId()
Example
constaccuntId=window.wallet.getAccountId();
Request sign in
Method: requestSignIn
/*** * @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.* @returns { accessKey } signed in access key*/requestSignIn({ contractId, methodNames })
// Clean the signed in accessKey from storagesignOut()
Example
window.wallet.signOut();
Check the account is signed in
Method: isSignedIn
/*** Check the current account is signed in with initial contract* @returns true or false*/isSignedIn()
Example
if(window.wallet.isSignedIn()){// TODO}
Listen the current accmount changed
Method: onAccountChanged
/*** Listen the current account changed* @param {*} callback (accountId) => { "TODO if account has changed" }*/onAccountChanged(callback)
Example
window.wallet.onAccountChanged((changedAccountId)=>{// TODO if account has changed});
Sign and send transaction
Method: signAndSendTransaction
/*** * @param {*} contractId contract account id* @param {*} methodName contract method name* @param {*} receiverId receiver account id* @param {*} amount transfer near amount* @param {*} params function call arguments* @param {*} gas transaction gas* @param {*} deposit transaction attached deposit* @param {*} usingAccessKey If 'true', will using access key to make function call and no need to request user to sign this transaction. Set 'false' will popup a notification window to request user to sign this transaction.* * @returns the result of send transaction*/signAndSendTransaction({ contractId, methodName, receiverId, amount, params, gas, deposit, usingAccessKey })
Examples
// Normal transfer// Transfer NEAR to othersconstoptions={receiverId: 'xxxx.testnet',amount: parseNearAmount('1'),usingAccessKey: false,}constres=awaitwindow.wallet.signAndSendTransaction(options);
// Contract method function call// Say hi to the contract by using access keyconstoptions={contractId: 'dev-1635836502908-29682237937904',methodName: 'sayHi',usingAccessKey: true,}constres=awaitwindow.wallet.signAndSendTransaction(options);
// Contract method function call// Deposit storage to wrap.testnetconstoptions={contractId: 'wrap.testnet',methodName: 'storage_deposit',params: {account_id: window.wallet.accountId,registration_only: true,},gas: parseNearAmount('0.00000000003'),deposit: parseNearAmount('0.00125'),}constres=awaitwindow.wallet.signAndSendTransaction(options);
// Contract method function call// Swap NEAR to wNEARconstoptions={contractId: 'wrap.testnet',methodName: 'near_deposit',deposit: parseNearAmount('1'),
gas,// optional
deposit,// optional,usingAccessKey: false,}constres=awaitwindow.wallet.signAndSendTransaction(options);
// Contract method function call// Send wNEAR to othersconstoptions={contractId: 'wrap.testnet',methodName: 'ft_transfer',params: {received_id: 'xxxx.testnet',amount: '1000000000000000000',},
gas,// optional
deposit,// optional,usingAccessKey: false,}constres=awaitwindow.wallet.signAndSendTransaction(options);