Skip to content

Instantly share code, notes, and snippets.

View percybolmer's full-sized avatar

ProgrammingPercy percybolmer

View GitHub Profile
package main
import (
"github.com/rs/zerolog/log"
)
func main() {
// Log with service name
log.Info().
package main
import (
"log"
zlog "github.com/rs/zerolog/log"
)
func main() {
log.Print("Hello")
zlog.Print("Hello")
// getContractAddress returns the address of the contract
// hardcoded :)
function getContractAddress() {
// replace this to match your contract address
return "0x083863013a6b34a4a265eb6ff696daf35071c48e";
}
const HDWalletProvider = require('@truffle/hdwallet-provider');
const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();
module.exports = {
networks: {
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard BSC port (default: none)
network_id: "*", // Any network (default: none)
useEffect(() => {
// Only get profile if we are completly loaded
if (loaded && (accounts !== 0)) {
// get user info
getUserProfile()
// Subscribe to Stake events
// Options allows us to specify filters so we dont grab all events, in this case we only select our current account in metamask
let options = {
filter: {
address: [accounts[0]]
// stake will trigger a stake on the users behalf
function stake() {
// When we trigger Transactions we should use send instead of call
// We should also calculate the GAS cost so we can apply the correct amount of gas
devToken.methods.stake(1000).estimateGas({from: accounts[0]})
.then((gas) => {
// We now have the gas amount, we can now send the transaction
devToken.methods.stake(1000).send({
from: accounts[0],
gas: gas
// 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]);
}
return (
<div className="App">
<header className="App-header">
<p> Welcome to your DAPP</p>
<p>The total supply is {totalSupply}</p>
<p>Account balance: {accountBalance}</p>
<button onClick={stake}><p>Stake</p></button>
</header>
const [accountBalance, setAccountBalance] = useState(0);
const [accountStakes, setAccountStakes] = useState({});
return (
<div className="App">
<header className="App-header">
<p> Welcome to your DAPP</p>
<p>Tokens total supply is {totalSupply}</p>
<button onClick={stake}><p>Stake</p></button>
</header>
</div>