Last active
August 6, 2021 11:02
-
-
Save percybolmer/59b976f2b337cc80cf7ce3275a1d9f60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// getUserProfile will fetch account information from the block chain network | |
async function getUserProfile() { | |
// Let's grab the tokens total supply, the method is named the same as in the Solidity code, and add call() to execute it. | |
// We can also get the response using a callback. I do recommend this method most times as we dont know how long the executions can take. | |
call(devToken.methods.totalSupply, setTotalSupply); | |
// balanceOf Requires input argument of the account to grab, so let's grab the first available account for now | |
call(devToken.methods.balanceOf, setAccountBalance, accounts[0]); | |
call(devToken.methods.hasStake, setAccountStakes, accounts[0]); | |
} | |
// call takes in a function to execute and runs a given callback on the response | |
function call(func, callback, ...args) { | |
// Trigger the function with the arguments | |
func(...args).call() | |
.then((result) => { | |
// Apply given callback, this is our stateSetters | |
callback(result); | |
}) | |
.catch((error) => { | |
throw new Error(error); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment