JavaScript
Use Adena Wallet SDK with JavaScript
The Adena Wallet SDK provides the necessary tools to integrate the Adena Wallet into JavaScript-based applications, enabling interactions with both the Adena Wallet and TM2 Wallet for signing transactions, managing accounts, and more.
For full documentation and source code, visit the Adena Wallet SDK Repository
Install the SDK
To add the Adena Wallet SDK to your project, you can use either npm or yarn.
Using npm:
npm install @adena-wallet/sdkUsing yarn:
yarn add @adena-wallet/sdkQuick Start
Get started with the Adena Wallet SDK by following this simple guide.
Import the SDK
Start by importing the SDK into your project.
import { AdenaSDK } from '@adena-wallet/sdk';
const adenaSDK = AdenaSDK.createAdenaWallet();If you're using the wallet from tm2-js-client, you can create as follows:
Connect to a Wallet
Connect to a user's wallet to begin interacting with it.
Fetch Account Details
Once the wallet is connected, you can retrieve user account details.
Advanced Features
The Adena Wallet SDK supports a wide range of functionalities beyond connecting wallets and fetching account details. Here are some additional key features you can implement.
connectWallet
Connects to a wallet via the SDK.
Example:
disconnectWallet
Disconnects from a wallet via the SDK.
Example:
getConnectionState
Retrieves the current connection state of a wallet.
Example:
onConnectionChange
Sets up a listener for connection state changes.
Example:
offConnectionChange
Removes a previously set connection state change listener.
Example:
isConnected
Checks if a wallet is currently connected.
Example:
getAccount
Retrieves account information from the connected wallet.
Example:
getNetwork
Retrieves network information from the connected wallet.
Example:
switchNetwork
Switches the wallet to a different network.
Example:
addNetwork
Adds a new network to the wallet.
Example:
signTransaction
Signs a transaction with the connected wallet.
Example:
broadcastTransaction
Broadcasts a signed transaction to the network.
Example:
onChangeAccount
Sets up a listener for account changes.
Example:
onChangeNetwork
Sets up a listener for network changes.
Example:
Create a Transaction
You can use a helper module called TransactionBuilder to generate encoded transaction data.
Transaction message generation functions
makeMsgSendMessage
Generates a MsgSend of the bank transaction message.
Example:
makeAddPackageMessage
Generate a AddPackage of the VM transaction message.
Example:
makeMsgCallMessage
Generate a MsgCall of the VM transaction message.
Example:
makeMsgRunMessage
Generates a MsgRun of the vm transaction message.
Example:
Error Handling and Debugging
Use console.error to capture detailed logs for any issues encountered during interactions with the SDK. Ensure you handle promise rejections to avoid unexpected application crashes.
For example:
Last updated