Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@acala-network/bodhi

Package Overview
Dependencies
Maintainers
0
Versions
212
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@acala-network/bodhi

  • 2.8.10
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
661
increased by279.89%
Maintainers
0
Weekly downloads
 
Created
Source

@acala-network/bodhi.js

bodhi.js SDK provides utils for interaction with Acala EVM+:

  • a BodhiProvider that extends ethers.js Provider
  • a BodhiSigner that extends ethers.js Signer

Getting Started

install

yarn add @acala-network/bodhi
# or
npm install @acala-network/bodhi

create a wallet

import { WsProvider } from "@polkadot/api";
import { createTestPairs } from "@polkadot/keyring/testingPairs";
import { SubstrateSigner, BodhiProvider, BodhiSigner } from "@acala-network/bodhi";

const provider = new BodhiProvider({
  provider: new WsProvider("ws://localhost:9944")
});

// create a substrate payload signer, dapps will use an extension signer
const { alice } = createTestPairs();
const signer = new SubstrateSigner(provider.api.registry, alice);

const wallet = new BodhiSigner(provider, alice.address, signer);
// or from pair
const wallet = BodhiSigner.fromPair(provider, alice);

alternatively, for a quick testing setup, we can use the getTestUtils helper, which basically encapsulates the above setup.

import { getTestUtils } from '@acala-network/bodhi';
const { wallets, provider, pairs } = await getTestUtils('ws://localhost:9944');
const alice = pairs[0];
const wallet = wallets[0];

use the wallet

now that we have an eth compatible wallet (signer), we can use it with any eth toolings.

For example we can use it with waffle to deploy a contract

import { deployContract } from "ethereum-waffle";
const instance = await deployContract(wallet, contractAbi, params);

or use with ethers to interact with existing contracts

const instance = new ethers.Contract(address, contractAbi, wallet);
await instance.callSomeFunction();

Concepts

You may notice there are so many "providers" and "signers", basically there are two from substrate world (WsProvider, SubstrateSigner), and two from traditional eth world (Signer, Provider).

Here is a brief hierachy of how they work together:

  • BodhiSigner: top level eth signer (wallet), compatible with ethers.js AbstractSigner, can be directly used by any eth toolings, such as ethers, waffle, etc.
    • SubstrateSigner: substrate payload signer, usually from keyring pair or an extension wallet, such as polkadotjs or talisman
    • Provider (BodhiProvider): eth provider for eth related communications, mostly compatible with ethers.js AbstractProvider
      • WsProvider: provides websocket connection with substrate based chains, used by BodhiProvider internally

TODO: maybe a graph is better.

Evm+ Specific Features

besides classic signer methods, we have some additional features available only for Evm+. For a comprehensive list please checkout here

await wallet.claimEvmAccounts(evmAddress);  // bind an evm address to the signer substrate address
await wallet.claimDefaultAccount();         // bind default evm address to the signer substrate address
wallet.computeDefaultEvmAddress();          // you know it
await wallet.queryEvmAddress();             // Get the signers EVM address if it has claimed one.

Examples

Checkout bodhi-examples for some real apps that integrate bodhi signers, with some extra cool features (such as batch transactions).

FAQs

Package last updated on 24 Oct 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc