()
| 16 | ) |
| 17 | |
| 18 | func SendTx() { |
| 19 | |
| 20 | account := common.HexToAddress("You Account") |
| 21 | |
| 22 | data, _ := ioutil.ReadFile("key") |
| 23 | fmt.Println(data) |
| 24 | fmt.Println(string(data)) |
| 25 | |
| 26 | client, err := ethclient.Dial("The RPC interface address") |
| 27 | if err != nil { |
| 28 | log.Fatal("Unable to connect to network:", err) |
| 29 | } |
| 30 | |
| 31 | // Get the Balance |
| 32 | balance, err := client.BalanceAt(context.Background(), account, nil) |
| 33 | |
| 34 | fbalance := new(big.Float) |
| 35 | fbalance.SetString(balance.String()) |
| 36 | bnbValue := new(big.Float).Quo(fbalance, big.NewFloat(math.Pow10(18))) |
| 37 | |
| 38 | fmt.Println(bnbValue) |
| 39 | |
| 40 | if err != nil { |
| 41 | log.Fatal(err) |
| 42 | } |
| 43 | |
| 44 | privateKey, err := crypto.HexToECDSA("You private Key") |
| 45 | if err != nil { |
| 46 | log.Fatal(err) |
| 47 | } |
| 48 | |
| 49 | publicKey := privateKey.Public() |
| 50 | |
| 51 | publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) |
| 52 | |
| 53 | if !ok { |
| 54 | log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey") |
| 55 | } |
| 56 | |
| 57 | fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) |
| 58 | |
| 59 | nonce, err := client.PendingNonceAt(context.Background(), fromAddress) |
| 60 | if err != nil { |
| 61 | log.Fatal(err) |
| 62 | } |
| 63 | |
| 64 | // 18 zeros, transfer 1 ETH |
| 65 | value := big.NewInt(1000000000000000000) |
| 66 | |
| 67 | gasLimit := uint64(21000) |
| 68 | |
| 69 | // Get the estimate Gas Price (Based on the average gas price in previous transaction gas price) |
| 70 | gasPrice, err := client.SuggestGasPrice(context.Background()) |
| 71 | if err != nil { |
| 72 | log.Fatal(err) |
| 73 | } |
| 74 | |
| 75 | // Construct the target Address |
nothing calls this directly
no outgoing calls
no test coverage detected