@abmprotocl/dtbtc 中文文档教程

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

Dai.js

GitHub 许可证NPM构建状态覆盖状态捆绑包大小

Dai.js 是一个 JavaScript 库,可以轻松地在 MakerDAO 之上构建应用程序' s Dai 稳定币系统。 您可以使用 Maker 的合约开立抵押债务头寸、提取 Dai 贷款、在 OasisDEX 上交易代币等等。

该库具有可插入的、基于服务的架构,允许用户在将 Maker 功能集成到现有基础架构中时实现最大程度的控制。 它还包括开箱即用的便捷配置预设、强大的智能合约状态检查器以及对前端和后端应用程序的支持。

Maker 的整套合约最终都可以通过这个库访问——包括 DAO 治理和即将发布的多抵押品——但在当前的 alpha 版本中,功能仅限于以下领域:

  • Opening and shutting CDPs
  • Locking and unlocking collateral
  • Withdrawing and repaying Dai
  • Automated token conversions
  • Token contract functionality for WETH, PETH, MKR, Dai, and ETH
  • Buying and selling MKR and Dai with built-in DEX integration

Usage

使用 NPM 或 Yarn 安装库:

npm install @makerdao/dai

然后包括it:

import Maker from '@makerdao/dai';
// or:
const Maker = require('@makerdao/dai');

Dai 转账

import Maker from '@makerdao/dai';
const maker = Maker.create('test');
await maker.authenticate();

transferDai(address, amount) {
  const dai = maker.service('token').getToken('DAI');
  return dai.transfer(address, amount);
 }

示例: 使用 CDP 示例:

import Maker from '@makerdao/dai';
const maker = Maker.create('test');
await maker.authenticate();
const cdp = await maker.openCdp();
const info = await cdp.getInfo();
console.log(info);

完整文档请参考 docs.makerdao.com

对于使用该库的示例代码,请查看此存储库

Developing

  1. git clone https://github.com/makerdao/dai.js
  2. yarn install
  3. Install testchain - git submodule update --init --recursive
  4. Install dapptools - curl https://dapp.tools/install | sh

Running the unit tests

测试套件配置为在 Ganache 测试链上运行。 在使用 yarn test 运行测试之前,测试链将从部署了 Maker 合约的快照开始。

如果您想在更改代码时重新运行测试,请使用 yarn test:watch

如果要启动测试链并使其保持运行,请使用 yarn test:net

Running the integration tests

还有通过 Kovan 测试网络或以太坊主网络发送交易的自动化测试。 要使用它们,首先将适当网络的私钥设置为环境变量:

export PRIVATE_KEY="0x..."

然后,使用 yarn test:kovanyarn test:mainnet 运行测试。

由于这些网络的运行速度比 Ganache 慢得多,您可能需要设置调试环境变量(以便在此过程中查看一些相关输出):

export DEBUG="dai:testing"

您也可以使用命令 yarn test:integration 在本地测试网络上运行这些测试。

Handling changes to contract code

如果您已将合约代码更改部署到测试链,请运行 scripts/install-testchain-outputs.sh 以将任何更新的 ABI 文件和合约地址复制到它们的预期位置。

Commands

  • yarn build:cjs - create a commonJS build in dist folder
  • yarn build:umd - create a UMD build in umd folder
  • yarn lint - run an ESLint check
  • yarn coverage - run code coverage and generate report in the coverage folder
  • yarn test - start a test chain and run all tests
  • yarn test:watch - start a test chain and run all tests in watch mode
  • yarn test:net - just start a test chain
  • yarn test:kovan - run integration tests on Kovan
  • yarn test:mainnet - run integration tests on mainnet
  • yarn test:integration - run integration tests on Ganache

Changelog

0.17.0

  • BREAKING CHANGE: Importing a file directly from the package must now be done by prefixing the path with dist. E.g. /contracts/addresses/kovan.json now becomes /dist/contract/addresses/kovan.json.

License

Dai.js 可根据代码中包含的 MIT 许可证获得。

[测试网址]:https://travis-ci.org/makerdao/dai.js

Dai.js

GitHub LicenseNPMBuild StatusCoverage StatusBundle Size

Dai.js is a JavaScript library that makes it easy to build applications on top of MakerDAO's Dai Stablecoin System. You can use Maker's contracts to open Collateralized Debt Positions, withdraw loans in Dai, trade tokens on OasisDEX, and more.

The library features a pluggable, service-based architecture, which allows users maximal control when integrating the Maker functionality into existing infrastructures. It also includes convenient configuration presets for out-of-the-box usability, a powerful smart contract state inspector, and support for both front-end and back-end applications.

Maker's entire suite of contracts will eventually be accessible through this library—including the DAO governance and the upcoming multi-collateral release—but functionality is limited in the current alpha version to the following areas:

  • Opening and shutting CDPs
  • Locking and unlocking collateral
  • Withdrawing and repaying Dai
  • Automated token conversions
  • Token contract functionality for WETH, PETH, MKR, Dai, and ETH
  • Buying and selling MKR and Dai with built-in DEX integration

Usage

Use NPM or Yarn to install the library:

npm install @makerdao/dai

Then include it:

import Maker from '@makerdao/dai';
// or:
const Maker = require('@makerdao/dai');

Example for transferring Dai:

import Maker from '@makerdao/dai';
const maker = Maker.create('test');
await maker.authenticate();

transferDai(address, amount) {
  const dai = maker.service('token').getToken('DAI');
  return dai.transfer(address, amount);
 }

Example for using CDPs:

import Maker from '@makerdao/dai';
const maker = Maker.create('test');
await maker.authenticate();
const cdp = await maker.openCdp();
const info = await cdp.getInfo();
console.log(info);

For full documentation, please refer to docs.makerdao.com.

For example code that consumes the library, check out this repository.

Developing

  1. git clone https://github.com/makerdao/dai.js
  2. yarn install
  3. Install testchain - git submodule update --init --recursive
  4. Install dapptools - curl https://dapp.tools/install | sh

Running the unit tests

The test suite is configured to run on a Ganache test chain. Before running the tests with yarn test, the test chain will start from a snapshot that has the Maker contracts deployed to it.

If you want to re-run the tests whenever you make a change to the code, use yarn test:watch.

If you want to start a test chain and leave it running, use yarn test:net.

Running the integration tests

There are also automated tests that send transactions through either the Kovan test network or the Ethereum main network. To use them, first set your private key for the appropriate network to an environment variable:

export PRIVATE_KEY="0x..."

Then, use either yarn test:kovan or yarn test:mainnet to run the tests.

Since these networks run much more slowly than Ganache, you might want to set the debug environment variable (in order to see some relevant output along the way):

export DEBUG="dai:testing"

You can also run these tests on the local test network with the command yarn test:integration.

Handling changes to contract code

If you have deployed contract code changes to the testchain, run scripts/install-testchain-outputs.sh to copy any updated ABI files and contract addresses to their expected locations.

Commands

  • yarn build:cjs - create a commonJS build in dist folder
  • yarn build:umd - create a UMD build in umd folder
  • yarn lint - run an ESLint check
  • yarn coverage - run code coverage and generate report in the coverage folder
  • yarn test - start a test chain and run all tests
  • yarn test:watch - start a test chain and run all tests in watch mode
  • yarn test:net - just start a test chain
  • yarn test:kovan - run integration tests on Kovan
  • yarn test:mainnet - run integration tests on mainnet
  • yarn test:integration - run integration tests on Ganache

Changelog

0.17.0

  • BREAKING CHANGE: Importing a file directly from the package must now be done by prefixing the path with dist. E.g. /contracts/addresses/kovan.json now becomes /dist/contract/addresses/kovan.json.

License

Dai.js is available under the MIT license included with the code.

[tests-url]: https://travis-ci.org/makerdao/dai.js

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