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/sdk

Using yarn:

yarn add @adena-wallet/sdk

Quick 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.create();

Connect to a Wallet

Connect to a user's wallet to begin interacting with it.

adenaSDK.connectWallet().then(() => {
  console.log('Wallet connected successfully.');
}).catch((error) => {
  console.log('Failed to connect:', error);
});

Fetch Account Details

Once the wallet is connected, you can retrieve details about the user's account.

adenaSDK.getAccount().then((account) => {
  console.log('Account details:', account);
}).catch((error) => {
  console.log('Failed to fetch account details:', error);
});

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.

Sign a Transaction

To sign a transaction using the connected wallet:

const transactionRequest = {
  tx: Tx.create({ // Tx is defined in @gnolang/tm2-js-client.
    messages: [],
    fee: {
      gasFee: '1ugnot',
      gasWanted: 1_000_000
    },
    memo: ""
  },
  broadcastType: BroadcastType.SYNC,
)};

adenaSDK.signTransaction(transactionRequest)
  .then((signedTransaction) => {
    console.log('Transaction signed:', signedTransaction);
  })
  .catch((error) => {
    console.error('Failed to sign the transaction:', error);
  });

Send a Transaction

After signing, you can send the transaction:

const transactionRequest = {
  tx: Tx.create({ // Tx is defined in @gnolang/tm2-js-client.
    messages: [],
    fee: {
      gasFee: '1ugnot',
      gasWanted: 1_000_000
    },
    memo: ""
  },
  broadcastType: BroadcastType.SYNC,
)};

adenaSDK.broadcastTransaction(transactionRequest)
  .then((result) => {
    console.log('Transaction sent:', result);
  })
  .catch((error) => {
    console.error('Failed to send the transaction:', error);
  });

Disconnect from a Wallet

To disconnect the currently connected wallet:

adenaSDK.disconnectWallet();

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:

adenaSDK.connectWallet()
  .then(() => {
    // Proceed with further operations
  })
  .catch((error) => {
    // Log detailed error
    console.error('Error during wallet connection:', error);
    // Handle errors gracefully, such as showing user-friendly messages in the UI
  });

Last updated