# onblock

> onblock JavaScript SDK

Latest version **0.1.7** (published 2019-07-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install onblock
pnpm add onblock
yarn add onblock
bun add onblock
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.7 |
| Published | 2019-07-24 |
| First published | 2019-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 32.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | onblock-team |
| Maintainers | oasis-team |

## Links

- npm: https://www.npmjs.com/package/onblock
- npm.io page: https://npm.io/package/onblock

## Dependencies (2)

- [uuidv4](https://npm.io/package/uuidv4.md) ^4.0.0
- [eventemitter3](https://npm.io/package/eventemitter3.md) ^3.1.0

## Recent versions

- 0.1.7 (latest) — 2019-07-24
- 0.1.6 — 2019-06-06
- 0.1.5 — 2019-05-18
- 0.1.4 — 2019-05-18
- 0.1.3 — 2019-04-28
- 0.1.2 — 2019-04-28
- 0.1.1 — 2019-04-26
- 0.1.0 — 2019-04-20

## README

#onblock.js

JS SDK of OnBlock

## Installation
Using npm in your project
```bash
npm install onblock
```

## CDN
```javascript
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/onblock@0.1.7/dist/onblock.min.js"></script>
```
exports to window.OnBlock global.

## Usage

### IOST
```javascript
import OnBlock from 'onblock'
import IOST form 'iost'


const isInOnBlock = OnBlock.isInOnBlock()
if(isInOnBlock){
  OnBlock.enable().then((name) => {
    if(!name) return;

    const user = OnBlock.account
    const iost = OnBlock.newIOST(IOST)

  })
}

// get user wallet
OnBlock.getOnBlockAccountInfo()
.then(data => {
  console.log(data.balances)
})


//tx
const tx = iost.callABI('contractName', 'actionName', 'memo');
tx.setGas(1,200000)
tx.addApprove('iost', '10')

iost.signAndSend(tx)
.on('pending', (hash) => {})
.on('success', (data) => {})
.on('failed', (err) => {})

```

### EOS
```javascript
import OnBlock from 'onblock'
import Eos from 'eosjs'


const isInOnBlock = OnBlock.isInOnBlock()
if(isInOnBlock){
  OnBlock.enable().then((name) => {
    if(!name) return;

    const network = {
      blockchain: 'eos',
      host: 'proxy.eosnode.tools',
      port: 443,
      protocol: 'https',
      chainId: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906'
    }
    const eos = OnBlock.newEOS(Eos, network)
    // const eos = OnBlock.newEOS(Eos)

  })
}

// get user wallet
OnBlock.getOnBlockAccountInfo()
.then(data => {
  console.log(data.balances)
})


//tx
eos.transfer(account.name, 'onblockblock', '0.0001 EOS', account.name).then(res => {
    console.log('sent: ', res);
}).catch(err => {
    console.error('error: ', err);
});
```

### Tron

```javascript
import OnBlock from 'onblock'
import TronWeb from 'tronweb'


const isInOnBlock = OnBlock.isInOnBlock()
if(isInOnBlock){
  window.tronWeb = OnBlock.newTron(TronWeb)

}
// get user address
const address = window.tronWeb.defaultAddress.base58

//tx
const contractAddress = 'xxx'
const contract = await window.tronWeb.contract().at(contractAddress)
const result = await contract.play('xxx').send({ callValue: 0 })

```

---
_Source: https://npm.io/package/onblock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
