symbol-wallet-lib v0.1.0
Symbol Wallet Lib
JavaScript SDK for interacting with the Symbol Extension Wallet.
Installation
Install the library as an npm package into your project.
npm install symbol-wallet-lib
Usage
Initialization and connection to wallet
Import SymbolExtension
module from the package.
import { SymbolExtension } from 'symbol-wallet-lib';
Create an instance of SymbolExtension
and register the provider.
Once a provider is registered, check if it's connected to the wallet.
Then the interaction with the wallet can be started.
const symbolExtension = new SymbolExtension();
await symbolExtension.registerProvider();
if (symbolExtension.isConnected()) {
console.log('The wallet is accessible and ready for communication.');
}
Sending a Transaction
To create transactions you can use symbol-sdk.
Then the transaction needs to be serialized. Example with symbol-sdk
:
const transactionPayload = uint8ToHex(transaction.serialize());
Send a transaction to the wallet for confirmation by the user.
try {
await symbolExtension.requestTransaction(transactionPayload);
console.log('Transaction is waiting for a user confirmation.');
}
catch (error) {
console.error(error);
}
Getting an account info
Request the account info permission. The promise is getting resolved as soon as the request is delivered to the wallet.
await symbolExtension.requestAccountPermission();
Request the account info.
try {
const currentUserAccount = await symbolExtension.getAccountInfo();
console.log(
`User's public key: "${currentUserAccount.publicKey}`,
`Network type: "${currentUserAccount.networkType}"`
);
}
catch (error) {
console.error(error);
}
Please note that it can take some time for the user to review and accept the request.
Calling getAccountInfo()
without a user permission will be rejected with an error.
Development
Set up tools and environment
You need to have Node.js installed. Node includes npm as its default package manager.
Install dependencies
Install dependencies with npm:
npm install
Test
npm run test
Build
Build production (distribution) files in dist folder:
npm run build
It generates CommonJS (in dist/cjs folder), ES Modules (in dist/esm folder), bundled and minified UMD (in dist/umd folder), as well as TypeScript declaration files (in dist/types folder).
1 year ago