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
connectWalletConnects to a wallet via the SDK.
Example:
disconnectWallet
disconnectWalletDisconnects from a wallet via the SDK.
Example:
getConnectionState
getConnectionStateRetrieves the current connection state of a wallet.
Example:
onConnectionChange
onConnectionChangeSets up a listener for connection state changes.
Example:
offConnectionChange
offConnectionChangeRemoves a previously set connection state change listener.
Example:
isConnected
isConnectedChecks if a wallet is currently connected.
Example:
getAccount
getAccountRetrieves account information from the connected wallet.
Example:
getNetwork
getNetworkRetrieves network information from the connected wallet.
Example:
switchNetwork
switchNetworkSwitches the wallet to a different network.
Example:
addNetwork
addNetworkAdds a new network to the wallet.
Example:
signTransaction
signTransactionSigns a transaction with the connected wallet.
Example:
broadcastTransaction
broadcastTransactionBroadcasts a signed transaction to the network.
Example:
onChangeAccount
onChangeAccountSets up a listener for account changes.
Example:
onChangeNetwork
onChangeNetworkSets 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
makeMsgSendMessageGenerates a MsgSend of the bank transaction message.
Example:
makeAddPackageMessage
makeAddPackageMessageGenerate a AddPackage of the VM transaction message.
Example:
makeMsgCallMessage
makeMsgCallMessageGenerate a MsgCall of the VM transaction message.
Example:
makeMsgRunMessage
makeMsgRunMessageGenerates 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