-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction_raw_send.go
37 lines (29 loc) · 981 Bytes
/
transaction_raw_send.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
package main
import (
"context"
"encoding/hex"
"fmt"
"log"
"os"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rlp"
)
func main() {
client, err := ethclient.Dial(os.Getenv("RINKEBY_INFURA_URL"))
if err != nil {
log.Fatalf("ethclient connection error: %s", err.Error())
}
rawTx := "f86d8202b28477359400825208944592d8f8d7b001e72cb26a73e4fa1806a51ac79d880de0b6b3a7640000802ca05924bde7ef10aa88db9c66dd4f5fb16b46dff2319b9968be983118b57bb50562a001b24b31010004f13d9a26b320845257a6cfc2bf819a3d55e3fc86263c5f0772"
rawTxBytes, err := hex.DecodeString(rawTx)
if err != nil {
log.Fatalf("try hex decode string error: %s", err.Error())
}
tx := new(types.Transaction)
rlp.DecodeBytes(rawTxBytes, &tx)
err = client.SendTransaction(context.Background(), tx)
if err != nil {
log.Fatalf("try send transaction error: %s", err.Error())
}
fmt.Println("Transaction Hash: ", tx.Hash().Hex())
}