0.0.6 • Published 4 years ago
tribute-utils v0.0.6
🏺 Tribute-Utils
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>
);
}