Skip to content

Instantly share code, notes, and snippets.

@mikekoro
Created February 22, 2021 18:25
Show Gist options
  • Save mikekoro/4d465d9be9d46909086260e918e7edf2 to your computer and use it in GitHub Desktop.
Save mikekoro/4d465d9be9d46909086260e918e7edf2 to your computer and use it in GitHub Desktop.
import Web3 from 'web3';
export const getMetamask = (windowObject) => {
if(!windowObject.web3) {
return false
}
return windowObject.web3;
}
export const getWeb3 = () => {
return Web3;
}
export const connectToMetamask = async(windowObject) => {
if(!windowObject || !windowObject.ethereum) {
throw new Error("Window object or Metamask not found!")
}
try {
let enable = await windowObject.ethereum.enable()
return enable;
} catch(err) {
return err;
}
}
export const getContract = async({ web3, abi, address}) => {
try {
let contract = await new web3.eth.Contract(abi, address);
return contract;
} catch(err) {
return err;
}
}
export const approve = async({contract, spender, amount, from }) => {
try {
let response = await contract.methods.approve(
spender,
amount
).send({from: from});
return response;
} catch(err) {
return err;
}
}
export const stake = async({contract, amount, from }) => {
try {
let response = await contract.methods.stakeNuvo(
amount
).send({from: from});
return response;
} catch(err) {
return err;
}
}
export const allocation = async({contract, owner, spender }) => {
try {
let response = await contract.methods.allowance(
owner, // my eth address
spender, // dao contract
).call({from: owner});
return response;
} catch(err) {
return err;
}
}
export const getStakeHistory = async({ contract }) => {
try {
let response = await contract.getPastEvents("Transfer", {
fromBlock: 0,
toBlock: 'latest'
})
return response;
}
catch(err) {
return err;
}
}
export const getStakeInfo = async({ contract, address, id }) => {
try {
let response = await contract.methods.getStake(id).call({from: address})
return response;
}
catch(err) {
return err;
}
}
export const Nuvo_Dao_JSON = [{"name": "Transfer", "inputs": [{"type": "address", "name": "_from", "indexed": true}, {"type": "address", "name": "_to", "indexed": true}, {"type": "uint256", "name": "_tokenId", "indexed": true}], "anonymous": false, "type": "event"}, {"name": "Approval", "inputs": [{"type": "address", "name": "_owner", "indexed": true}, {"type": "address", "name": "_approved", "indexed": true}, {"type": "uint256", "name": "_tokenId", "indexed": true}], "anonymous": false, "type": "event"}, {"name": "ApprovalForAll", "inputs": [{"type": "address", "name": "_owner", "indexed": true}, {"type": "address", "name": "_operator", "indexed": true}, {"type": "bool", "name": "_approved", "indexed": false}], "anonymous": false, "type": "event"}, {"name": "AdministratorRenounced", "inputs": [{"type": "address", "name": "_previousAdmin", "indexed": true}], "anonymous": false, "type": "event"}, {"name": "AdministratorTransferred", "inputs": [{"type": "address", "name": "_previousAdmin", "indexed": true}, {"type": "address", "name": "_newAdmin", "indexed": true}], "anonymous": false, "type": "event"}, {"name": "Paused", "inputs": [], "anonymous": false, "type": "event"}, {"name": "Unpaused", "inputs": [], "anonymous": false, "type": "event"}, {"outputs": [], "inputs": [{"type": "address", "name": "_nuvo_address"}], "constant": false, "payable": false, "type": "constructor"}, {"name": "supportsInterface", "outputs": [{"type": "bool", "name": ""}], "inputs": [{"type": "bytes32", "name": "_interfaceID"}], "constant": true, "payable": false, "type": "function", "gas": 1266}, {"name": "renounceAdministrator", "outputs": [], "inputs": [], "constant": false, "payable": false, "type": "function", "gas": 22371}, {"name": "transferAdministrator", "outputs": [], "inputs": [{"type": "address", "name": "_newAdmin"}], "constant": false, "payable": false, "type": "function", "gas": 37921}, {"name": "balanceOf", "outputs": [{"type": "uint256", "name": ""}], "inputs": [{"type": "address", "name": "_owner"}], "constant": true, "payable": false, "type": "function", "gas": 1492}, {"name": "ownerOf", "outputs": [{"type": "address", "name": ""}], "inputs": [{"type": "uint256", "name": "_tokenId"}], "constant": true, "payable": false, "type": "function", "gas": 1498}, {"name": "getStake", "outputs": [{"type": "tuple", "name": "", "components": [{"type": "uint256", "name": "nuvo_staked"}, {"type": "uint256", "name": "stake_timestamp"}]}], "inputs": [{"type": "uint256", "name": "_tokenId"}], "constant": true, "payable": false, "type": "function", "gas": 2819}, {"name": "getApproved", "outputs": [{"type": "address", "name": ""}], "inputs": [{"type": "uint256", "name": "_tokenId"}], "constant": true, "payable": false, "type": "function", "gas": 2455}, {"name": "isApprovedForAll", "outputs": [{"type": "bool", "name": ""}], "inputs": [{"type": "address", "name": "_owner"}, {"type": "address", "name": "_operator"}], "constant": true, "payable": false, "type": "function", "gas": 1669}, {"name": "transferFrom", "outputs": [], "inputs": [{"type": "address", "name": "_from"}, {"type": "address", "name": "_to"}, {"type": "uint256", "name": "_tokenId"}], "constant": false, "payable": false, "type": "function", "gas": 319703}, {"name": "safeTransferFrom", "outputs": [], "inputs": [{"type": "address", "name": "_from"}, {"type": "address", "name": "_to"}, {"type": "uint256", "name": "_tokenId"}], "constant": false, "payable": false, "type": "function"}, {"name": "safeTransferFrom", "outputs": [], "inputs": [{"type": "address", "name": "_from"}, {"type": "address", "name": "_to"}, {"type": "uint256", "name": "_tokenId"}, {"type": "bytes", "name": "_data"}], "constant": false, "payable": false, "type": "function"}, {"name": "approve", "outputs": [], "inputs": [{"type": "address", "name": "_approved"}, {"type": "uint256", "name": "_tokenId"}], "constant": false, "payable": false, "type": "function", "gas": 41906}, {"name": "setApprovalForAll", "outputs": [], "inputs": [{"type": "address", "name": "_operator"}, {"type": "bool", "name": "_isApproved"}], "constant": false, "payable": false, "type": "function", "gas": 39191}, {"name": "burn", "outputs": [], "inputs": [{"type": "uint256", "name": "_tokenId"}], "constant": false, "payable": false, "type": "function", "gas": 129929}, {"name": "mint", "outputs": [{"type": "bool", "name": ""}], "inputs": [{"type": "address", "name": "_to"}, {"type": "uint256", "name": "_nuvo_staked"}], "constant": false, "payable": false, "type": "function", "gas": 184894}, {"name": "transferNuvo", "outputs": [{"type": "bool", "name": ""}], "inputs": [{"type": "address", "name": "_to"}, {"type": "uint256", "name": "_value"}], "constant": false, "payable": false, "type": "function", "gas": 7037}, {"name": "pause", "outputs": [], "inputs": [], "constant": false, "payable": false, "type": "function", "gas": 38455}, {"name": "unpause", "outputs": [], "inputs": [], "constant": false, "payable": false, "type": "function", "gas": 23482}, {"name": "destroy", "outputs": [], "inputs": [], "constant": false, "payable": false, "type": "function", "gas": 35637}, {"name": "stakeNuvo", "outputs": [], "inputs": [{"type": "uint256", "name": "_amount"}], "constant": false, "payable": false, "type": "function", "gas": 195789}, {"name": "unstakeNuvo", "outputs": [], "inputs": [{"type": "uint256", "name": "_tokenId"}], "constant": false, "payable": false, "type": "function", "gas": 96196}, {"name": "name", "outputs": [{"type": "string", "name": ""}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 7326}, {"name": "symbol", "outputs": [{"type": "string", "name": ""}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 7356}, {"name": "totalMinted", "outputs": [{"type": "uint256", "name": ""}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 1961}, {"name": "nuvo_address", "outputs": [{"type": "address", "name": ""}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 1991}, {"name": "paused", "outputs": [{"type": "bool", "name": ""}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 2021}, {"name": "stakes__nuvo_staked", "outputs": [{"type": "uint256", "name": ""}], "inputs": [{"type": "uint256", "name": "arg0"}], "constant": true, "payable": false, "type": "function", "gas": 2238}, {"name": "stakes__stake_timestamp", "outputs": [{"type": "uint256", "name": ""}], "inputs": [{"type": "uint256", "name": "arg0"}], "constant": true, "payable": false, "type": "function", "gas": 2274}]
export const Nuvo_Cash_JSON = [{"constant":true,"inputs":[],"name":"mintingFinished","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_amount","type":"uint256"}],"name":"mint","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_subtractedValue","type":"uint256"}],"name":"decreaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"finishMinting","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_addedValue","type":"uint256"}],"name":"increaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":true,"stateMutability":"payable","type":"constructor"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"burner","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[],"name":"MintFinished","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment