@iov/cli
Command line interface for iov core
Last updated 13 days ago by webmaster128 .
Apache-2.0 · Repository · Original npm · Tarball · package.json
$ cnpm install @iov/cli 
SYNC missed versions from official npm registry.

@iov/cli

npm version

Installation and first run

The iov-cli executable is available via npm. We recommend local installations to your demo project. If you don't have one yet, just mkdir iov-cli-installation && cd iov-cli-installation && yarn init -y.

locally with yarn

$ yarn add @iov/cli --dev
$ ./node_modules/.bin/iov-cli

locally with npm

$ npm install @iov/cli --save-dev
$ ./node_modules/.bin/iov-cli

globally with yarn

$ yarn global add @iov/cli
$ iov-cli

globally with npm

$ npm install -g @iov/cli
$ iov-cli

How to use the IOV-Core command line interface

  1. Install @iov/cli and run iov-cli as shown above
  2. Start a local BNS blockchain as described in scripts/bnsd/README.md
  3. Play around as in the following example code:
> const profile = new UserProfile();
> const signer = new MultiChainSigner(profile);
> const { connection } = await signer.addChain(createBnsConnector("ws://localhost:23456"));
> const chainId = connection.chainId();

> chainId
'test-chain-esuZ1V'

> const wallet = profile.addWallet(Ed25519HdWallet.fromMnemonic("degree tackle suggest window test behind mesh extra cover prepare oak script"));

> profile.getIdentities(wallet.id)
[]

> const faucet = await profile.createIdentity(wallet.id, chainId, HdPaths.iov(0))

> faucet.pubkey
{ algo: 'ed25519',
  data:
   Uint8Array [
     224,
     42, ...

> profile.setIdentityLabel(faucet, "blockchain of value faucet")

> profile.getIdentities(wallet.id)
[ { chainId: 'test-chain-esuZ1V',
    pubkey: { algo: 'ed25519', data: [Uint8Array] } } ]

> const faucetAddress = signer.identityToAddress(faucet);
> faucetAddress
'tiov1k898u78hgs36uqw68dg7va5nfkgstu5z0fhz3f'
> (await connection.getAccount({ address: faucetAddress })).balance

> const recipient = await profile.createIdentity(wallet.id, chainId, HdPaths.iov(1));
> const recipientAddress = signer.identityToAddress(recipient);

> .editor
const sendTx = await connection.withDefaultFee<SendTransaction & WithCreator>({
  kind: "bcp/send",
  creator: faucet,
  recipient: recipientAddress,
  memo: "My first transaction",
  amount: {
    quantity: "33123456789",
    fractionalDigits: 9,
    tokenTicker: "CASH" as TokenTicker,
  },
});
^D
> await signer.signAndPost(sendTx);
> (await connection.getAccount({ address: recipientAddress })).balance;

> await connection.searchTx({ sentFromOrTo: faucetAddress });
> await connection.searchTx({ sentFromOrTo: recipientAddress });
  1. Congratulations, you sent your first money!
  2. Add an additional wallet
> profile.wallets.value
[ { id: 'ReYESw51lsOOr8_X', label: undefined } ]

> const wallet2 = profile.addWallet(Secp256k1HdWallet.fromMnemonic("organ wheat manage mirror wish truly tool trumpet since equip flight bracket"))

> profile.wallets.value
[ { id: 'ReYESw51lsOOr8_X', label: undefined },
  { id: 'FtIcQqMWcRpEIruk', label: undefined } ]

> profile.getIdentities(wallet.id)
[ { chainId: 'test-chain-esuZ1V',
    pubkey: { algo: 'ed25519', data: [Uint8Array] } } ]

> profile.getIdentities(wallet2.id)
[]

> profile.setWalletLabel(wallet.id, "ed")
> profile.setWalletLabel(wallet2.id, "secp")

> profile.wallets.value
[ { id: 'ReYESw51lsOOr8_X', label: 'ed' },
  { id: 'FtIcQqMWcRpEIruk', label: 'secp' } ]
  1. Now store to disk
> const db = levelup(leveldown('./my_userprofile_db'))
> await profile.storeIn(db, "secret passwd")
  1. and restore
> const profileFromDb = await UserProfile.loadFrom(db, "secret passwd");
> profileFromDb
UserProfile {
  createdAt: 2018-07-04T16:07:14.583Z,
  keyring:
   Keyring { wallets: [ [Ed25519HdWallet], [Secp256k1HdWallet] ] },
  ...

Register a username on the IOV Name Service

Assuming you have a profile, a signer and a recipient identity with transactions associated from above

> .editor
const registrationTx = await connection.withDefaultFee<RegisterUsernameTx & WithCreator>({
  kind: "bns/register_username",
  creator: recipient,
  targets: [],
  username: "hans*iov",
});
^D
> await signer.signAndPost(registrationTx);
> const bnsConnection = connection as BnsConnection;
> await bnsConnection.getUsernames({ owner: recipientAddress });
[ { username: 'hans*iov',
    owner: 'tiov14cn8m57wtrlewmlnjucctsahpnxlj92l0crkvq',
    targets: [] } ]
> await bnsConnection.getUsernames({ username: "hans*iov" });
[ { username: 'hans*iov',
    owner: 'tiov14cn8m57wtrlewmlnjucctsahpnxlj92l0crkvq',
    targets: [] } ]

Disconnecting

When you are done using a WebSocket connection, disconnect the connection

> (await connection.getAccount({ address: faucetAddress })).balance
[ { quantity: '123456755876543211',
    fractionalDigits: 9,
    tokenTicker: 'CASH' } ]
> connection.disconnect()
undefined
> (await connection.getAccount({ address: faucetAddress })).balance
Error: Socket was closed, so no data can be sent anymore.
    at ...

Faucet usage

When using a Testnet, you can use the IovFaucet to receive tokens.

In this example we connect to a public test network.

> const mnemonic = Bip39.encode(Random.getBytes(16)).toString();
> mnemonic
'helmet album grow detail apology thank wire chef fame core private cargo'
> const profile = new UserProfile();
> const wallet = profile.addWallet(Ed25519HdWallet.fromMnemonic(mnemonic));

> const signer = new MultiChainSigner(profile);
> const { connection } = await signer.addChain(createBnsConnector("https://rpc.lovenet.iov.one"));
> const chainId = connection.chainId();

> const alice = await profile.createIdentity(wallet.id, chainId, HdPaths.iov(0));
> const aliceAddress = signer.identityToAddress(alice);

> const faucet = new IovFaucet("https://bns-faucet.lovenet.iov.one/");

> await faucet.credit(aliceAddress, "IOV" as TokenTicker)
> (await connection.getAccount({ address: aliceAddress })).balance
[ { quantity: '10000000000',
    fractionalDigits: 9,
    tokenTicker: 'IOV' } ]

License

This package is part of the IOV-Core repository, licensed under the Apache License 2.0 (see NOTICE and LICENSE).

Current Tags

  • 1.1.0                                ...           latest (13 days ago)

79 Versions

  • 1.1.0                                ...           13 days ago
  • 1.0.0                                ...           a month ago
  • 1.0.0-alpha.1                                ...           2 months ago
  • 1.0.0-alpha.0                                ...           2 months ago
  • 0.17.8                                ...           2 months ago
  • 0.17.7                                ...           2 months ago
  • 0.17.6                                ...           2 months ago
  • 0.17.5                                ...           2 months ago
  • 0.17.4                                ...           2 months ago
  • 0.17.3                                ...           2 months ago
  • 0.17.2                                ...           2 months ago
  • 0.17.1                                ...           3 months ago
  • 0.17.0                                ...           3 months ago
  • 0.16.3                                ...           3 months ago
  • 0.16.2                                ...           3 months ago
  • 0.16.1                                ...           3 months ago
  • 0.16.0                                ...           4 months ago
  • 0.16.0-alpha.4                                ...           4 months ago
  • 0.16.0-alpha.3                                ...           4 months ago
  • 0.16.0-alpha.2                                ...           4 months ago
  • 0.16.0-alpha.1                                ...           4 months ago
  • 0.16.0-alpha.0                                ...           4 months ago
  • 0.15.0                                ...           5 months ago
  • 0.14.5                                ...           5 months ago
  • 0.14.4                                ...           5 months ago
  • 0.14.3                                ...           6 months ago
  • 0.13.8                                ...           6 months ago
  • 0.14.2                                ...           6 months ago
  • 0.13.7                                ...           6 months ago
  • 0.14.1                                ...           7 months ago
  • 0.13.6                                ...           7 months ago
  • 0.13.5                                ...           7 months ago
  • 0.13.4                                ...           7 months ago
  • 0.14.0                                ...           7 months ago
  • 0.13.3                                ...           7 months ago
  • 0.13.2                                ...           7 months ago
  • 0.13.1                                ...           7 months ago
  • 0.13.0                                ...           8 months ago
  • 0.12.3                                ...           8 months ago
  • 0.13.0-alpha.0                                ...           8 months ago
  • 0.12.2                                ...           9 months ago
  • 0.12.1                                ...           9 months ago
  • 0.11.3                                ...           10 months ago
  • 0.12.0                                ...           10 months ago
  • 0.11.2                                ...           10 months ago
  • 0.11.1                                ...           10 months ago
  • 0.11.0                                ...           10 months ago
  • 0.11.0-alpha.1                                ...           10 months ago
  • 0.11.0-alpha.0                                ...           10 months ago
  • 0.10.4                                ...           10 months ago
  • 0.10.3                                ...           a year ago
  • 0.10.2                                ...           a year ago
  • 0.10.1                                ...           a year ago
  • 0.10.0                                ...           a year ago
  • 0.9.3                                ...           a year ago
  • 0.9.2                                ...           a year ago
  • 0.9.1                                ...           a year ago
  • 0.9.0                                ...           a year ago
  • 0.8.1                                ...           a year ago
  • 0.8.0                                ...           a year ago
  • 0.7.1                                ...           a year ago
  • 0.7.0                                ...           a year ago
  • 0.7.0-alpha.1                                ...           a year ago
  • 0.7.0-alpha.0                                ...           a year ago
  • 0.6.1                                ...           a year ago
  • 0.6.0                                ...           a year ago
  • 0.5.4                                ...           a year ago
  • 0.5.3                                ...           a year ago
  • 0.5.2                                ...           a year ago
  • 0.5.1                                ...           a year ago
  • 0.5.0                                ...           a year ago
  • 0.4.1                                ...           a year ago
  • 0.4.0                                ...           a year ago
  • 0.3.1                                ...           a year ago
  • 0.3.0                                ...           a year ago
  • 0.3.0-alpha.0                                ...           a year ago
  • 0.2.0                                ...           a year ago
  • 0.2.0-7                                ...           a year ago
  • 0.2.0-6                                ...           a year ago
Downloads
Today 0
This Week 0
This Month 107
Last Day 0
Last Week 81
Last Month 38
Dependencies (14)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |