@acala-network/bodhi 中文文档教程

发布于 3年前 浏览 18 项目主页 更新于 3年前

@acala-network/bodhi.js

bodhi.js SDK 实现了一个 web3 提供程序,以允许现有的以太坊 dApp 能够与 Acala EVM

如果您使用的是 mandala tc6,那么您应该使用@acala-network/bodhi@0.2.x、@acala-network/api@0.7.1、@polkadot/api@4.2.1。

Getting Started

  • Install dependencies
yarn

Documentation

大多数bodhi.js 的 api 与 ethers.js 兼容。 如果你不熟悉 ethers.js,你可以先看看它的文档

Provider

Provider 提供了一些 api用于与节点交互,是 ethers.js 抽象提供者

Creating Instances

new Provider( apiOptions )

apiOptions 的参数与为 polkadot.js 创建 apiPromise 实例时相同

import { options } from "@acala-network/api";
import { Provider } from "@acala-network/bodhi";
import { WsProvider } from "@polkadot/api";

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

Wallet

Wallet 类继承了 Signer,可以使用私钥对交易和消息进行签名。

Creating Instances

new Wallet( privateKey , provider? , keyringPair? )

“privateKey”是evm账户的私钥。 "provider" 是 Provider 的一个实例。 “keyringPair”是polkadot 的密钥对。 如果“keyringPair”为空,将生成一个密钥对 “私钥”。

import { Wallet } from "@acala-network/bodhi";
const wallet = new Wallet("0xaa397267eaee48b2262a973fdcab384a758f39a3ad8708025cfb675bb9effc20", provider)

Wallet.claimEvmAccounts()

使用“keyringpair”绑定一个由“privateKey”生成的evm账号。

wallet.claimEvmAccounts()

Examples

deploy a contract

import { deployContract } from "ethereum-waffle";
import ERC20Abi from "../build/ERC20Abi.json";
import { TestAccountSigningKey, Provider, Signer } from "@acala-network/bodhi";
import { WsProvider } from "@polkadot/api";
import { createTestPairs } from "@polkadot/keyring/testingPairs";

const provider = new Provider({
  provider: new WsProvider("ws://127.0.0.1:9944"),
});

const testPairs = createTestPairs();

const signingKey = new TestAccountSigningKey(provider.api.registry);

signingKey.addKeyringPair(Object.values(testPairs));

const wallet = new Signer(provider, testPairs.alice.address, signingKey)

const tokenInstance = await deployContract(master, ERC20Abi, [1000]);

@acala-network/bodhi.js

bodhi.js SDK implements a web3 provider to allow existing Ethereum dApp to be able to interact with Acala EVM.

If you are using mandala tc6, then you should use @acala-network/bodhi@0.2.x, @acala-network/api@0.7.1, @polkadot/api@4.2.1.

Getting Started

  • Install dependencies
yarn

Documentation

Most of the api of bodhi.js is compatible with ethers.js. If you are not familiar with ethers.js, you can start by looking at its documentation

Provider

The Provider provides some api for interacting with nodes and is an instance of ethers.js AbstractProvider.

Creating Instances

new Provider( apiOptions )

apiOptions has the same parameters as when creating an instance of apiPromise for polkadot.js

import { options } from "@acala-network/api";
import { Provider } from "@acala-network/bodhi";
import { WsProvider } from "@polkadot/api";

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

Wallet

The Wallet class inherits Signer and can sign transactions and messages using a private key.

Creating Instances

new Wallet( privateKey , provider? , keyringPair? )

"privateKey" is the private key of evm's account. "provider" is an instance of Provider. "keyringPair" is a key pair for polkadot. If the "keyringPair" is empty, a key pair will be generated from the "privateKey".

import { Wallet } from "@acala-network/bodhi";
const wallet = new Wallet("0xaa397267eaee48b2262a973fdcab384a758f39a3ad8708025cfb675bb9effc20", provider)

Wallet.claimEvmAccounts()

Use "keyringpair" to bind an evm account generated by "privateKey".

wallet.claimEvmAccounts()

Examples

deploy a contract

import { deployContract } from "ethereum-waffle";
import ERC20Abi from "../build/ERC20Abi.json";
import { TestAccountSigningKey, Provider, Signer } from "@acala-network/bodhi";
import { WsProvider } from "@polkadot/api";
import { createTestPairs } from "@polkadot/keyring/testingPairs";

const provider = new Provider({
  provider: new WsProvider("ws://127.0.0.1:9944"),
});

const testPairs = createTestPairs();

const signingKey = new TestAccountSigningKey(provider.api.registry);

signingKey.addKeyringPair(Object.values(testPairs));

const wallet = new Signer(provider, testPairs.alice.address, signingKey)

const tokenInstance = await deployContract(master, ERC20Abi, [1000]);
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文