AvalancheJS - Avalanche平台 JavaScript 图书馆
概览
AvalancheJS是一个用于与Avalanche平台相接的JavaScript图书馆. 它使用TypeScript来构建,旨在同时支持浏览器和Node.js. AvalancheJS库允许您向Avalanche节点API发布命令.
使用AvalancheJS,开发者可以:
- 收回地址的余额
- 获取地址的 UTXOs
- 构建和签名交易
- 向X-Chain、P-Chain和C-Chain签发签名交易
- 在 X 、 P 和 C 链之间进行跨链互换
- 添加验证器和验证器
- 创建子网和块链
所需资源
AvalancheJS需要Node.js LTS版本20.11.1或更高版本来编译.
安装
利用国家预防机制一揽子计划
在您的项目中通过 npm 或者说 yarn。 。 。 .
用于通过 npm数字 :
npm install --save @avalabs/avalanchejs
用于通过 yarn数字 :
yarn add @avalabs/avalanchejs
从仓库构建
也可以将还原物直接拉倒并从零开始建造.
克隆 AvalancheJS 仓库 :
git clone https://github.com/ava-labs/avalanchejs.git
然后建造它:
npm run build
或者说
yarn build
在项目中使用 AvalancheJS
AvalancheJS 库可导入到您的现有项目中如下:
import { avm, pvm, evm } from '@avalabs/avalanchejs';
导入基本内容
import { avm /** X-chain */, pvm /** P-chain */, evm /** C-chain */, utils, secp256k1 } from "@avalabs/avalanchejs"
// example calls
const exportTx = avm.newExportTx(...) // constructs a new export tx from X
const addValidatorTx = pvm.newAddPermissionlessValidatorTx(...) // constructs a new add validator tx on P
const importTx = evm.newImportTx(...) // constructs a new import tx to C
const publicKeyBytes = utils.hexToBuffer(publicKeyHex)
const signature = secp256k1.signHash(bytes, privateKeyBytes)
请检查一下 examples 用于更多信息的文件夹.