forked from chenzhijie/go-web3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (35 loc) · 1.19 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"os"
"github.com/chenzhijie/go-web3"
"github.com/chenzhijie/go-web3/utils"
)
func main() {
// change to your rpc provider
var rpcProvider = "https://rpc.flashbots.net"
web3, err := web3.NewWeb3(rpcProvider)
if err != nil {
panic(err)
}
web3.Eth.SetAccount(os.Getenv("eth_privateKey"))
blockNumber, err := web3.Eth.GetBlockNumber()
if err != nil {
panic(err)
}
fmt.Println("Current block number: ", blockNumber)
fee, err := web3.Eth.EstimateFee()
if err != nil {
panic(err)
}
util := utils.Utils{}
fmt.Printf("base fee %v, %.3f Gwei\n", fee.BaseFee, util.FromWeiWithUnit(fee.BaseFee, utils.EtherUnitGWei))
fmt.Printf("max priority fee per gas %v, %.3f Gwei\n", fee.MaxPriorityFeePerGas, util.FromWeiWithUnit(fee.MaxPriorityFeePerGas, utils.EtherUnitGWei))
fmt.Printf("max fee per gas %v, %.3f Gwei\n", fee.MaxFeePerGas, util.FromWeiWithUnit(fee.MaxFeePerGas, utils.EtherUnitGWei))
fmt.Println("current account ", web3.Eth.Address())
receipt, err := web3.Eth.SyncSendEIP1559RawTransaction(web3.Eth.Address(), util.ToWei(0.01), 21000, fee.MaxPriorityFeePerGas, fee.MaxFeePerGas, nil)
if err != nil {
panic(err)
}
fmt.Printf("eip 1559 tx %v\n", receipt)
}