Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

azero-wallet-adapter

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

azero-wallet-adapter

Access Aleph Zero Wallet snap through a typed API

latest
Source
npmnpm
Version
0.3.1
Version published
Maintainers
1
Created
Source

azero-wallet-adapter

Usage

pnpm add azero-wallet-adapter

API

Follow the integration guide below for method usage and parameter handling.

(Note: For all methods, params is the data required by each method. It has different types depending on the function being called.)

1. Get Account Address

The getAccount method doesn't need any parameters.

import { getAccount, isSuccess } from 'azero-wallet-adapter';

const result: Result<GetAccountResult> = await getAccount();
if (isSuccess(result)) {
  console.log(result.data); // {address: "account address"}
} else {
  console.error(result.error);
}

2. Sign and Send Payload

This method requires the SignAndSendTransactionRequestParams type for its params. The response type is Result<SignAndSendExtrinsicTransactionResult>. The payload includes the transaction (hex string) and payload ( SignerPayloadJSON type).

import {
    signAndSendExtrinsicTransactionPayload,
    SignAndSendTransactionRequestParams,
    isSuccess
} from 'azero-wallet-adapter';

mport

const txParams: SignAndSendTransactionRequestParams = {transaction: /*...*/, payload: /*...*/}

signAndSendExtrinsicTransactionPayload(txParams).then(result => {
    if (isSuccess(result)) {
        // handle result transaction
    } else {
        // handle error
    }
});

3. Sign Payload

Like the previous method, but only signs the payload without sending it. This works with the SignSignerPayloadRequestParams.

import {
    signSignerPayload,
    SignSignerPayloadRequestParams,
    isSuccess
} from 'azero-wallet-adapter';

const signParams: SignSignerPayloadRequestParams = {payload: /*...*/};

signSignerPayload(signParams).then(result => {
    if (isSuccess(result)) {
        // handle result transaction
    } else {
        // handle error
    }
});

4. Transfer Native Assets

This function requires the TransferNativeAssetRequestParams type for its parameters.

import {
    transferNativeAsset,
    TransferNativeAssetRequestParams,
    isSuccess
} from 'azero-wallet-adapter';

const transferParams: TransferNativeAssetRequestParams = {
    recipient: /*...*/,
    amount: /*...*/
};

transferNativeAsset(transferParams).then(result => {
    if (isSuccess(result)) {
        // handle result transaction
    } else {
        // handle error
    }
});

5. Set the RPC URL

To set the RPC URL, you can use the setRpcUrl with SetRpcUrlRequestParams as its parameters.

import {
  setRpcUrl,
  SetRpcUrlRequestParams,
  isSuccess,
} from 'azero-wallet-adapter';

const rpcParams: SetRpcUrlRequestParams = { rpcUrl: 'http://my-rpc-url' };

setRpcUrl(rpcParams).then((result) => {
  if (isSuccess(result)) {
    // execute callback after RPC URL is set
  } else {
    // handle error
  }
});

License

This project is licensed under the GPL-3.0 License.

Keywords

aleph

FAQs

Package last updated on 16 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts