-
-
Save webmaster128/c364e98a0dcf98a6ee22e1e7a8a041e5 to your computer and use it in GitHub Desktop.
Getting started with web4 in pure JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd web4 | |
$ git checkout master && git pull && git clean -xdf && yarn install && yarn build && yarn run lerna run pack-node | |
$ node | |
> function wait(promise) { return require('deasync2').await(promise); } | |
> const web4 = require("./packages/iov-web4/dist/node") | |
> web4 | |
{ TransactionKind: | |
{ '0': 'Send', | |
'1': 'SetName', | |
'2': 'SwapOffer', | |
'3': 'SwapCounter', | |
'4': 'SwapClaim', | |
'5': 'SwapTimeout', | |
Send: 0, | |
SetName: 1, | |
SwapOffer: 2, | |
SwapCounter: 3, | |
SwapClaim: 4, | |
SwapTimeout: 5 }, | |
Ed25519SimpleAddressKeyringEntry: [Function: Ed25519SimpleAddressKeyringEntry], | |
Keyring: | |
{ [Function: Keyring] | |
deserializationRegistry: | |
Map { | |
'ed25519' => [Function], | |
'ed25519-simpleaddress' => [Function] } }, | |
UserProfile: [Function: UserProfile], | |
bnsConnector: [Function], | |
bnsFromOrToTag: [Function: fromOrToTag], | |
Web4Write: [Function: Web4Write], | |
withConnectors: [Function] } | |
> const { Ed25519SimpleAddressKeyringEntry, UserProfile, bnsConnector, bnsFromOrToTag, TransactionKind, Web4Write, withConnectors } = web4 | |
> const profile = new UserProfile(); | |
> profile.addEntry(Ed25519SimpleAddressKeyringEntry.fromMnemonic("degree tackle suggest window test behind mesh extra cover prepare oak script")) | |
> const faucet = wait(profile.createIdentity(0)) | |
> const knownChains = wait(withConnectors(wait(bnsConnector("wss://bov.wolfnet.iov.one")))); | |
> const writer = new Web4Write(profile, knownChains); | |
> const chainId = writer.chainIds()[0]; | |
> const reader = writer.reader(chainId); | |
> const faucetAddress = writer.keyToAddress(chainId, faucet.pubkey); | |
> wait(reader.getAccount({ address: faucetAddress })).data[0].balance | |
[ { whole: 99888, | |
fractional: 999998446, | |
tokenTicker: 'CASH', | |
tokenName: 'Second token of this chain', | |
sigFigs: 6 }, | |
{ whole: 100000, | |
fractional: 0, | |
tokenTicker: 'IOV', | |
tokenName: 'Main token of this chain', | |
sigFigs: 6 } ] | |
> wait(reader.searchTx({ tags: [bnsFromOrToTag(faucetAddress)] })); | |
[ { height: 135, | |
transaction: | |
{ kind: 'send', | |
recipient: [Object], | |
amount: [Object], | |
memo: 'My first payment', | |
chainId: 'test-chain-Cc61nX', | |
signer: [Object] }, | |
primarySignature: { nonce: [Object], publicKey: [Object], signature: [Object] }, | |
otherSignatures: [] }, | |
{ height: 153, | |
transaction: | |
{ kind: 'send', | |
recipient: [Object], | |
amount: [Object], | |
memo: 'Web4 write style', | |
chainId: 'test-chain-Cc61nX', | |
signer: [Object] }, | |
primarySignature: { nonce: [Object], publicKey: [Object], signature: [Object] }, | |
otherSignatures: [] } ] | |
... and so on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment