# @onboardmoney/sdk

wrap ethereum in sexy

[![Version](https://img.shields.io/npm/v/@onboardmoney/sdk.svg)](https://npmjs.org/package/@onboardmoney/sdk)
[![Downloads/week](https://img.shields.io/npm/dw/@onboardmoney/sdk.svg)](https://npmjs.org/package/@onboardmoney/sdk)
[![License](https://img.shields.io/npm/l/@onboardmoney/sdk.svg)](https://github.com/onboardmoney/onboard.money/blob/master/package.json)

# Install

```sh-session
$ npm install @onboardmoney/sdk
```

```sh-session
$ yarn add @onboardmoney/sdk
```

# Initialize

```ts
import {
  App,
  Policies,
  TxBatchInterface,
  TransactionReceipt,
} from '@onboardmoney/sdk'
import { PopulatedTransaction } from 'ethers'

const apiKey = 'ABCXYZ'
const network = 'mainnet' | 'ropsten' | 'rinkeby' | 'goerli' | 'kovan'
const onboardmoney = new App(apikey, `https://${network}.onboard.money`)
```

# App

```ts
// Fetch application ETH balance and address for gas payments
const { balance, relayAddress } = await onboardmoney.balance()
// { balance: 1.5, relayAddress: 0x1234 }

// Create a new application user
const { userAddress } = await onboardmoney.createUser()

// Create user transaction batch
const txBatch = {
  txs: [
    {
      from: userAddress, // required: user wallet address from which to send transaction (msg.sender)
      to: '0x1234', // required: destination address
      value: '1000000000000000000', // optional: amount of ETH to send in wei
      data: '0xabcd', // optional: smart contract calldata
    },
  ] as PopulatedTransaction[],
} as TxBatchInterface

// Evaluate if a batch of user transactions would succeed
const { success } = await onboardmoney.evaluateBatch(txBatch)

// Send a batch of user transactions to the network
const txReceipt = await onboardmoney.sendBatch()

// Query the current trust policy
const { policy } = await onboardmoney.getPolicy()

// Set a new trust policy
const newPolicy = Policies.self | Policies.custodied | Policies.multisig // required: new trust policy
const signerAddress = '0x1234' // optional: application signer address (only for 'self' and 'multisig' trust policy)
await onboardmoney.updatePolicy(newPolicy, signerAddress)

// Create user transaction batch with 'self' or 'multisig' trust policy
// Helper methods in development. Contact team for support on how to craft required data.
const txBatch = {
  txs: [
    {
      from: userAddress, // required: user address to send transaction from
      to: '0x1234', // required: destination address
      value: '1000000000000000000', // optional: amount of ETH to send in wei
      data: '0xabcd', // optional: smart contract calldata
      gasLimit: '100000', // required: gas limit permitted
      nonce: 15, // required: user wallet nonce
    },
  ] as PopulatedTransaction[],
  gasPrice: '10000000000', // optional: gas price in wei
  signatures: ['0xabcd'], // optional: application signature
} as TxBatchInterface
```
