Mock module for boardcasting and monitoring transaction
Import tbmmodule to your package
import (
"github.com/patcharanant/tbm-module"
)Creates a new tbm instance with your http provider.
// change to your provider url
url := "https://demo.example.com"
tbm, err := tbmmodule.Initiate(url)
if err != nil {
panic(err)
}create TrasactionPayload of the transaction you want to broadcast
payload := tbmmodule.TransactionPayload{
Symbol: "ETH",
Price: 4500,
Timestamp: uint64(time.Now().Unix()),
}Use TransactionPayload to Brodcast Trasaction function will return TxHash struct
txHash, err := tbm.Broadcast(payload)
if err != nil {
panic(err)
}
fmt.Println("Trasaction hash : ", tx_hash.Hash)Monitor transaction status. provide txHash from Broadcast function or create with tbmmodule.TxHash provide callback function when status change (ex. from pending to confirm will trigger a callback function)
tbm.Monitor(txHash, LogStatus) //txHash from Broadcast function
//OR
manualTxHash = tbmmodule.TxHash{Hash:"your hash here"}
tbm.Monitor(manualTxHash, callback)