@acentswap/acent 中文文档教程

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

????️ AcentJS

AcentJS 是用于与 AcentVM 交互的官方 Javascript SDK。 有关信息,请参阅 github.com/acentswap/acent-js

Installation

安装 AcentJS:

yarn add @acentswap/acent
# Or
npm install --save @acentswap/acent

Usage

入门教程 中描述了用法。

AcentVM network information

const AcentJS = require("@acentswap/acent");
const acentJS = new AcentJS();

// Print available methods
console.log(acentJS.acentVM);

// Query fees
acentJS.acentVM.queryFees().then(console.log);

Bridging BTC to Ethereum

这假设 window.ethereum 可用(例如在安装了 MetaMask 的浏览器中)。

请参阅 hdwallet-providerinfura.io 如果您使用 Node.js 而不是在浏览器中使用 AcentJS。

import { Bitcoin, Ethereum } from "@acentswap/chains";
import AcentJS from "@acentswap/acent";
import ethers from "ethers";

const mint = async () => {
    await window.ethereum.enable();
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    const signer = provider.getSigner();
    const address = await signer.getAddress();

    const lockAndMint = await new AcentJS("testnet").lockAndMint({
        asset: "BTC",
        from: Bitcoin(),
        to: Ethereum(provider.provider).Address(address),
    });

    console.log(`Deposit BTC to ${lockAndMint.gatewayAddress}`);

    lockAndMint.on("deposit", AcentJS.defaultDepositHandler);
};

mint().catch(console.error);

Bridging BTC from Ethereum back to the Bitcoin chain

import { Bitcoin, Ethereum } from "@acentswap/chains";
import AcentJS from "@acentswap/acent";
import ethers from "ethers";

const burn = async () => {
    await window.ethereum.enable();
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    const value = 2000000; // sats

    const burnAndRelease = await new AcentJS("testnet").burnAndRelease({
        asset: "BTC",
        to: Bitcoin().Address("miMi2VET41YV1j6SDNTeZoPBbmH8B4nEx6"),
        from: Ethereum(provider.provider).Account({ value }),
    });

    await burnAndRelease.burn();
    await burnAndRelease.release();
};

burn().catch(console.error);





Developer notes

Building

yarn run build
# or watch, to rebuild on new changes:
yarn run watch

Running tests

请参阅 ../test

????️ AcentJS

AcentJS is the official Javascript SDK for interacting with AcentVM. See github.com/acentswap/acent-js for information.

Installation

Install AcentJS:

yarn add @acentswap/acent
# Or
npm install --save @acentswap/acent

Usage

Usage is described in the Getting Started Tutorial.

AcentVM network information

const AcentJS = require("@acentswap/acent");
const acentJS = new AcentJS();

// Print available methods
console.log(acentJS.acentVM);

// Query fees
acentJS.acentVM.queryFees().then(console.log);

Bridging BTC to Ethereum

This assumes window.ethereum is available (e.g. in a browser with MetaMask installed).

See hdwallet-provider and infura.io if you are using AcentJS using Node.js instead of in a browser.

import { Bitcoin, Ethereum } from "@acentswap/chains";
import AcentJS from "@acentswap/acent";
import ethers from "ethers";

const mint = async () => {
    await window.ethereum.enable();
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    const signer = provider.getSigner();
    const address = await signer.getAddress();

    const lockAndMint = await new AcentJS("testnet").lockAndMint({
        asset: "BTC",
        from: Bitcoin(),
        to: Ethereum(provider.provider).Address(address),
    });

    console.log(`Deposit BTC to ${lockAndMint.gatewayAddress}`);

    lockAndMint.on("deposit", AcentJS.defaultDepositHandler);
};

mint().catch(console.error);

Bridging BTC from Ethereum back to the Bitcoin chain

import { Bitcoin, Ethereum } from "@acentswap/chains";
import AcentJS from "@acentswap/acent";
import ethers from "ethers";

const burn = async () => {
    await window.ethereum.enable();
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    const value = 2000000; // sats

    const burnAndRelease = await new AcentJS("testnet").burnAndRelease({
        asset: "BTC",
        to: Bitcoin().Address("miMi2VET41YV1j6SDNTeZoPBbmH8B4nEx6"),
        from: Ethereum(provider.provider).Account({ value }),
    });

    await burnAndRelease.burn();
    await burnAndRelease.release();
};

burn().catch(console.error);





Developer notes

Building

yarn run build
# or watch, to rebuild on new changes:
yarn run watch

Running tests

See ../test.

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