1.3.0 • Published 4 years ago

defizapjs v1.3.0

Weekly downloads
4
License
LGPLV2.1
Repository
github
Last release
4 years ago

DefiZap.js

DefiZap.js is a JavaScript library that allows easy access to DefiZap's smart contracts. This library can be used to directly interact with all of the Zaps available on DefiZap's platform.

Usage

Use npm or yarn to install the library:

npm i defizapjs
// or:
yarn add defizapjs

Include it in your app:

import DefiZap from 'defizapjs'
// or:
const DefiZap = require('defizapjs')

Example of using the Lender contract in browser (React):

import React, { Component } from 'React'
import DefiZap from 'defizapjs'

class LenderZap extends Component {

  componentDidMount() {
    (if window.ethereum)
    window.ethereum.enable() // Ask user permission to access metamask
    const defiZap = new DefiZap(window.web3)
    const lenderZap = defiZap.zap('Lender')
  }
  
  // !!! Initiates the sending of Ether !!!
  Zap = async (valueToSend) => {
    const gasPrice = await defiZap.getGasPrice() // Return an object containing fast, average, slow, gas prices in gwei
    let tx = await lender.invest(valueToSend, gasPrice.high) // gasPrice argument is optional
    console.log(tx)
  }
}

Example of using DefiZap in NodeJS

const DefiZap = require('defizapjs')

(async () => {
  const defiZap = new DefiZap() // No argument uses default infura/etherscan provider for read-only access
  const lenderZap = defiZap.zap('Lender')
  const lenderAddress = lenderZap.address
  console.log(lenderAddress)
})()

Supported Zaps

Instantiating supported zaps:

const lenderZap = defiZap.zap('Lender')
const ethMaximalistZap = defiZap.zap('EthMaximalist')
const moderateBullZap = defiZap.zap('ModerateBull')
const doubleBullZap = defiZap.zap('DoubleBull')
const superSaverZap = defiZap.zap('SuperSaver')

Sending Ether to the Zaps:

/*
.useFallback(string:valueInEtherToSend)
Returns a promise with the transaction details (object)
*/ 

const tx = await doubleBullZap.useFallback(valueToSend) 
1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago