LoginSignup
2
2

More than 3 years have passed since last update.

libra-coreでweb-client-walletの作成から、送金まで

Last updated at Posted at 2019-09-18

はじめに

Libra関連のjsライブラリが続々と出ていて、現状だと知る限りこのような選択肢があるようです。

SDK

https://github.com/perfectmak/libra-core
https://github.com/bandprotocol/libra-web
https://github.com/bonustrack/libra-grpc

ついでにViewerとしては、次のようなものが用意されています。

Viewer

https://www.libravista.com/
https://libexplorer.com/

LibravistaのAPIなども公開されているので、ここからAPIを通じて、mintなどを試すこともできます。
https://api-testnet.libravista.com/doc/

今回は、試しに、libra-coreを使ってwalletを生成したいと思います。
(本家のREADMEと同じ手順)

実装

env

//nodeのversionは12以上
$ nodebrew ls-remote
$ nodebrew install-binary v12.10.0
$ nodebrew use v12.10.0

install

$ npm install libra-core --save

アドレス作成~mint~確認まで

試しに10000Libraをwalletにmintします

users.js
var express = require('express');
const libra_core = require("libra-core");
var router = express.Router();
router.get('/mint', function (req, res, next) {
  const LibraWallet = libra_core.LibraWallet;
  const LibraClient = libra_core.LibraClient;
  const LibraNetwork = libra_core.LibraNetwork;
  const wallet = new LibraWallet();
  const account = wallet.newAccount();
  async function mint(account, amount) {
    const client = new LibraClient({
      network: LibraNetwork.Testnet
    });
    await client.mintWithFaucetService(account.getAddress(), amount * 1e6);
  }
  mint(account, 10000);
  res.json({
    status: "ok",
    address: account.getAddress().toHex()
  });
});

スクリーンショット 2019-09-18 17.54.56.png

おしまい

ちょいちょいtestnetのupdateも実施されているので、これらSDKも影響を受けることがありそうな予感。

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2