Skip to content

Commit

Permalink
Example to calculate fee
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Nov 6, 2020
1 parent b0fb974 commit b6897dd
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions examples/calculate_fee/calculate_fee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"log"

"github.com/tonicpow/go-minercraft"
)

func main() {

// Create a new client
client, err := minercraft.NewClient(nil, nil)
if err != nil {
log.Fatalf("error occurred: %s", err.Error())
}

// Select the miner
miner := client.MinerByName(minercraft.MinerTaal)

// Get a fee quote from a miner
var response *minercraft.FeeQuoteResponse
if response, err = client.FeeQuote(miner); err != nil {
log.Fatalf("error occurred: %s", err.Error())
}

// Example Tx Size (computed from the rawTx.ToBytes())
txSizeInBytes := uint64(441) // The Tx is 441 bytes in size, let's get the fee for that Tx

// Get the fee for a specific tx size (for mining and for data)
var fee uint64
if fee, err = response.Quote.CalculateFee(minercraft.FeeCategoryMining, minercraft.FeeTypeStandard, txSizeInBytes); err != nil {
log.Fatalf("error occurred: %s", err.Error())
}

// Display the results
log.Printf("miner: %s", response.Miner.Name)
log.Printf("tx size in bytes: %d and mining fee: %d", txSizeInBytes, fee)
}

0 comments on commit b6897dd

Please sign in to comment.