0.0.6 • Published 4 years ago

tribute-utils v0.0.6

Weekly downloads
9
License
MIT
Repository
github
Last release
4 years ago

🏺 Tribute-Utils

npm package Build Status Maintainability Language grade: JavaScript FOSSA Status npm.io

A utility to interact with the rDAI contracts.

Usage

tribute.getInfo()

{
  allocations: [array],
  balance: [number],
  unallocated_balance: [number],
  unclaimed_balance: [number]
}

...

Example

import React, { useState } from 'react';
import Tribute from 'tribute-utils';
import { ethers } from 'ethers';
import { CONTRACTS } from '../../helpers/constants';
import DAIabi from '../../../contracts/dai';
import rDAIabi from '../../../contracts/rDai';

export default function UserAccount() {
  const [state, setState] = useState();

    // 1. enable metamask
    if (window.ethereum) {
      let address = await window.ethereum.enable();
      try {
        if (
          typeof window.ethereum !== 'undefined' ||
          typeof window.web3 !== 'undefined'
        ) {
          let walletProvider = new ethers.providers.Web3Provider(
            window.web3.currentProvider
          );
          // connect to contracts on the network
          const rDAIContract = new ethers.Contract(
            CONTRACTS.rtoken.kovan,
            rDAIabi,
            walletProvider
          );
          const DAIContract = new ethers.Contract(
            CONTRACTS.dai.kovan,
            DAIabi,
            walletProvider
          );
          // create the Tribute object
          const tribute = new Tribute(
            DAIContract,
            rDAIContract,
            walletProvider,
            address
          );
          const userDetails = await tribute.getInfo();
          console.log(userDetails);
          setState(state => {
            return setState(
              ...state,
              { tribute },
              { userDetails },
            );
          });
        }
      } catch (error) {
        console.log('Web3 Loading Error: ', error.message);
      }
    }
  }
  return (
    <div>
      {JSON.stringify(userDetails)}
    </div>
  );
}

License

FOSSA Status

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.1

4 years ago