// Subscribe to pending transactions from blocknative.com
Subscribe to pending transactions from blocknative.com
// Subscribe to pending transactions from blocknative . com
func main() {
	apiKey := flag.String("apikey", "", "blocknative API key")
	outputFile := flag.String("output", "blocknative-tx.json", "The output file")
	flag.Parse()
	if *apiKey == "" || *outputFile == "" {
		flag.Usage()
		return
	}
	client, err := clients.NewBlocknativeClient(*apiKey, "ethereum", "bsc-main", nil, nil)
	if err != nil {
		log.Fatal(err)
	}
	signals := make(chan os.Signal, 1)
	signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
	stopCh := make(chan struct{})
	pendingTxCh := make(chan pojo.TxData)
	err = client.Subscribe(stopCh, pendingTxCh)
	if err != nil {
		log.Fatal(err)
	}
	go utils.Run(pendingTxCh, stopCh, *outputFile)
	<-signals
	log.Println("Ctrl+C detected, exiting...")
	close(stopCh)
	time.Sleep(1 * time.Second) 
}
func main ( ) { apiKey := flag . String ( " " , " " , " " ) outputFile := flag . String ( " " , " " , " " ) flag . Parse ( ) if * apiKey == " " || * outputFile == " " { flag . Usage ( ) return } client , err := clients . NewBlocknativeClient ( * apiKey , " " , " " , nil , nil ) if err != nil { log . Fatal ( err ) } signals := make ( chan os . Signal , 1 ) signal . Notify ( signals , syscall . SIGINT , syscall . SIGTERM ) stopCh := make ( chan struct { } ) pendingTxCh := make ( chan pojo . TxData ) err = client . Subscribe ( stopCh , pendingTxCh ) if err != nil { log . Fatal ( err ) } go utils . Run ( pendingTxCh , stopCh , * outputFile ) <- signals log . Println ( " " ) close ( stopCh ) time . Sleep ( 1 * time . Second ) }
Subscribe to pending transactions from blocknative.com
Subscribe to pending transactions from blocknative . com
// catch Ctrl+C // give some time for other goroutines to stop