@_koi/sdk 中文文档教程
Koi JavaScript SDK
Koi.js 库使 node.js 和 javascript/typescript 应用程序能够轻松地与开放的 Koi 网络进行交互。
Steps to Interact with the SDK in your Project
将 sdk 添加到您的项目中
您可以使用 npm 或 yarn
npm i @_koi/sdk
yarn add @_koi/sdk
- Add the Koi-tools module to your script and then initialize the koi class.
import * as kweb from "@_koi/sdk/web.js";
const tools = new kweb.Web();
或与 CommonJS 一起
const kweb = require("@_koi/sdk/web");
const tools = new kweb.Web();
使用或使用 bundle
<script src="koi_tools.js"></script>
...
const kweb = koi_tools.koi_web;
const tools = new kweb.Web();
注意:此库经常更改,因此如果 npm i @_koi/sdk
不起作用,请检查 beta 版本在版本部分下的 NPM 上或手动构建包(请参阅下面的 #Build 部分)。
- Optional - Add the Arweave module to your project if your app plans to directly transact with the permaweb outside of using the Koi-tools library
const Arweave = require("arweave");
const arweave = Arweave.init({
host: "arweave.net",
port: 443,
protocol: "https"
});
创建一个 RSA 钱包密钥
请注意,当您将项目签入 GitHub 时,钱包地址不应保存在您的项目内部
var walletKeyLocation = "path/to/wallet.json";
如果您没有钱包,您可以从 koi.rocks 或位于 faucet.arweave.org 的 Arweave 水龙头。
- Define a function to bootstrap your app and utilize the koi-tools
loadWallet
.
async function main() {
const jwk = await tools.loadFile(walletPath);
await tools.loadWallet(jwk);
}
main();
如果您只是使用本地捆绑器进行测试,您还可以使用 await tools.generateWallet()
为该运行时创建自定义密钥文件。
- Check out the test folder for examples of how to interact with koi-tools.
Build
NPM
yarn install
yarn build
yarn publish dist
对于 Beta 版本
- append
-beta.N
todist/package.json
version where N is the beta version - use
yarn publish dist --tag beta
,使用 yarn test
Webpack
yarn install
yarn bundle
进行测试 使用 yarn test-bundle
进行测试
Koi JavaScript SDK
The Koi.js library enables node.js and javascript/typescript applications to easily interact with the open Koi network.
Steps to Interact with the SDK in your Project
Add the sdk to your project
You can use either npm or yarn
npm i @_koi/sdk
yarn add @_koi/sdk
- Add the Koi-tools module to your script and then initialize the koi class.
import * as kweb from "@_koi/sdk/web.js";
const tools = new kweb.Web();
or with CommonJS
const kweb = require("@_koi/sdk/web");
const tools = new kweb.Web();
or using the bundle
<script src="koi_tools.js"></script>
...
const kweb = koi_tools.koi_web;
const tools = new kweb.Web();
Note: This library changes often, so if npm i @_koi/sdk
does not work, check for beta releases on NPM under the versions section or manually build the package (See #Build section below).
- Optional - Add the Arweave module to your project if your app plans to directly transact with the permaweb outside of using the Koi-tools library
const Arweave = require("arweave");
const arweave = Arweave.init({
host: "arweave.net",
port: 443,
protocol: "https"
});
Create an RSA Wallet Key
Note that the wallet address should not be held inside of your project when you check the project into GitHub
var walletKeyLocation = "path/to/wallet.json";
If you don't have a wallet, you can get one from the faucet at koi.rocks or the Arweave faucet at faucet.arweave.org.
- Define a function to bootstrap your app and utilize the koi-tools
loadWallet
.
async function main() {
const jwk = await tools.loadFile(walletPath);
await tools.loadWallet(jwk);
}
main();
If you are just testing with a local bundler, you can also use await tools.generateWallet()
to create a custom key file just for that runtime.
- Check out the test folder for examples of how to interact with koi-tools.
Build
NPM
yarn install
yarn build
yarn publish dist
For beta releases
- append
-beta.N
todist/package.json
version where N is the beta version - use
yarn publish dist --tag beta
Test with yarn test
Webpack
yarn install
yarn bundle
Test with yarn test-bundle