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
package main | |
import ( | |
"github.com/rs/zerolog/log" | |
) | |
func main() { | |
// Log with service name | |
log.Info(). |
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
package main | |
import ( | |
"log" | |
zlog "github.com/rs/zerolog/log" | |
) | |
func main() { | |
log.Print("Hello") | |
zlog.Print("Hello") |
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
// getContractAddress returns the address of the contract | |
// hardcoded :) | |
function getContractAddress() { | |
// replace this to match your contract address | |
return "0x083863013a6b34a4a265eb6ff696daf35071c48e"; | |
} |
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
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) |
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
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]] |
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
// 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 |
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]); | |
} |
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
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> |
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
const [accountBalance, setAccountBalance] = useState(0); | |
const [accountStakes, setAccountStakes] = useState({}); |