0.1.8-rc4 • Published 3 years ago

@spankchain-readonly/spankbank-web3 v0.1.8-rc4

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

spankbank-web3: A JavaScript/TypeScript + Web3 Interface to the SpankBank

For a demo, see: https://spankchain.github.io/spankbank-web3/

For the actual SpankBank, see: https://bank.spankchain.com

Using spankbank in Your App

  1. Add the package::

    $ yarn add @spankdev/spankbank-web3

    Where f1b39c8998 is the commit to pin (note: in the future this will be replaced with a tag).

  2. Use the SpankBank and Token::

    import { SpankBank, Token } from '@spankdev/spankbank-web3'

    let spankbank = new SpankBank('0xaad6cdac26aed0894d55bfaf2d3252c6084f5fc4') spankbank .getSpankPoints('0x8ec75ef3adf6c953775d0738e0e7bd60e647e5ef', 1) .then(spankPoints => { console.log('You have', spankPoints, 'spankPoints in period 1!') })

    let spankToken = new Token('0x374f46dc892ecdc9db8bc704175f0485e5185851') spankToken .approve('0xaad6cdac26aed0894d55bfaf2d3252c6084f5fc4', 69) .then(async txHash => { console.log('Approval transaction:', txHash) let receipt = await spankbank.waitForTransactionReceipt(txHash) console.log('Receipt:', receipt) })

Using with the Ledger Nano

To use with the Ledger Nano, use the provided LedgerWeb3Wrapper::

let ledgerWrapper = new LedgerWeb3Wrapper({
  // These parameters are optional. If they are not provided, Metamask
  // will be queried for the networkId, and the corresponding Infura
  // RPC endpoint will be used.
  networkId: 1,
  rpcUrl: 'https://mainnet.infura.io/metamask',
  // Any ledger request (for example, to sign a transaction) will take
  // this long to timeout. This number should be set to about 7 seconds
  // to detect the presence of a Ledger device (7 seconds has been
  // determined by experimentation to be a good balance between false
  // negatives and a long wait for a true negative). The
  // ``setLedgerTimeoutSeconds`` method can also be used to change the
  // timeout after instantiation.
  ledgerTimeoutSeconds: 30,
}}

// Wait for the ledger to load.
// This may throw a MetamaskError with ``metamaskError == 'LEDGER_LOCKED'``
// if the ledger is unplugged, locked, or the Ethereum app hasn't been
// started. Unfortuantely there doesn't seem to be a better way to
// distinguish between these cases.
// Additionally, it will take ``ledgerTimeoutSeconds`` (default: 30)
// seconds to fail with ``LEDGER_LOCKED``.
ledgerWrapper.then(
  () => console.log('Ledger ready!'),
  err => {
    if (err.metamaskError == 'LEDGER_NOT_SUPPORTED') {
      // The error message will describe the issue
      console.log(err.message)
    } else if (err.metamaskError == 'LEDGER_LOCKED') {
      console.log('The ledger is unplugged, locked, or the Ethereum app is not running')
    } else {
      console.log('Error connecting to ledger:', err)
  }
)

let sb = new SpankBank('0xaad6cdac26aed0894d55bfaf2d3252c6084f5fc4', ledgerWrapper)

Note: HTTPS must be used even when developing locally. The simplest way to do that is with ngrok (https://ngrok.com/)::

$ ngrok http --host-header=rewrite 6933
...
Forwarding                    https://db0a61c0.ngrok.io -> localhost:6933

Logging

By default, logs will be sent to console. This can be changed by calling setSpankBankLogger with any console-compatible logger::

import { setSpankBankLogger } from '@spankdev/spankbank-web3'

setSpankBankLogger({ info: (...args) => { myLog.info(args.join(' ')) }, ... })

Developing

To develop, run::

$ yarn
$ npm start

And be sure to re-build before pushing::

$ npm run build

Testing

To setup the test environment:

  1. Ensure that ganache (testrpc) is running::

    $ npm install -g ganache-cli $ ganache-cli --gas 1

  2. Run the tests::

    $ npm run test

Note: the tests use (essentially)::

$ cd node_modules/spankbank/
$ yarn
$ truffle deploy --reset

Before each test to deploy the smart contract.

API Overview

See: spankbank.ts (which will eventually be documented here)

0.1.8-rc4

3 years ago

0.1.8-rc2

3 years ago

0.1.8-rc1

3 years ago

0.1.8-rc3

3 years ago

0.1.6-rc2

3 years ago

0.1.8-rc0

3 years ago

0.1.7

3 years ago

0.1.6-rc1

3 years ago

0.1.3-rc82

3 years ago

0.1.3-rc83

3 years ago

0.1.3-rc84

3 years ago

0.1.3-rc85

3 years ago

0.1.3-rc86

3 years ago

0.1.3-rc87

3 years ago

0.1.3-rc88

3 years ago

0.1.3-rc89

3 years ago

0.1.3-rc81

3 years ago

0.1.3-rc80

3 years ago

0.1.3-rc79

3 years ago

0.1.3-rc78

3 years ago

0.1.3-rc73

3 years ago

0.1.3-rc74

3 years ago

0.1.3-rc75

3 years ago

0.1.3-rc76

3 years ago

0.1.3-rc77

3 years ago

0.1.3-rc67

3 years ago

0.1.3-rc68

3 years ago

0.1.3-rc69

3 years ago

0.1.3-rc70

3 years ago

0.1.3-rc71

3 years ago

0.1.3-rc72

3 years ago

0.1.3-rc64

3 years ago

0.1.3-rc65

3 years ago

0.1.3-rc66

3 years ago

0.1.3-rc63

3 years ago

0.1.3-rc50

3 years ago

0.1.3-rc52

3 years ago

0.1.3-rc53

3 years ago

0.1.3-rc54

3 years ago

0.1.3-rc10

3 years ago

0.1.3-rc55

3 years ago

0.1.3-rc11

3 years ago

0.1.3-rc56

3 years ago

0.1.3-rc12

3 years ago

0.1.3-rc57

3 years ago

0.1.3-rc13

3 years ago

0.1.3-rc58

3 years ago

0.1.3-rc14

3 years ago

0.1.3-rc59

3 years ago

0.1.3-rc15

3 years ago

0.1.3-rc16

3 years ago

0.1.3-rc17

3 years ago

0.1.3-rc18

3 years ago

0.1.3-rc19

3 years ago

0.1.3-rc4

3 years ago

0.1.3-rc5

3 years ago

0.1.3-rc6

3 years ago

0.1.3-rc7

3 years ago

0.1.3-rc8

3 years ago

0.1.3-rc9

3 years ago

0.1.3-rc60

3 years ago

0.1.3-rc61

3 years ago

0.1.3-rc62

3 years ago

0.1.3-rc20

3 years ago

0.1.3-rc21

3 years ago

0.1.3-rc22

3 years ago

0.1.3-rc23

3 years ago

0.1.3-rc24

3 years ago

0.1.3-rc25

3 years ago

0.1.3-rc26

3 years ago

0.1.3-rc27

3 years ago

0.1.3-rc28

3 years ago

0.1.3-rc29

3 years ago

0.1.3-rc30

3 years ago

0.1.3-rc31

3 years ago

0.1.3-rc32

3 years ago

0.1.3-rc33

3 years ago

0.1.3-rc34

3 years ago

0.1.3-rc35

3 years ago

0.1.3-rc36

3 years ago

0.1.3-rc37

3 years ago

0.1.3-rc38

3 years ago

0.1.3-rc39

3 years ago

0.1.3-rc40

3 years ago

0.1.3-rc41

3 years ago

0.1.3-rc42

3 years ago

0.1.3-rc43

3 years ago

0.1.3-rc44

3 years ago

0.1.3-rc45

3 years ago

0.1.3-rc46

3 years ago

0.1.3-rc47

3 years ago

0.1.3-rc48

3 years ago

0.1.3-rc49

3 years ago

0.1.3-rc3

3 years ago

0.1.3-rc2

3 years ago

0.1.3-rc1

3 years ago

0.1.3-rc0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago