-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (58 loc) · 2.14 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"context"
"crypto/ecdsa"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
)
func main() {
client, err := ethclient.Dial("https://rinkeby.infura.io")
if err != nil {
fmt.Printf("Houve falha ao conectar com Rinkeby via infuria: %+v", err)
}
pvtkey, err := crypto.HexToECDSA("84152329cd53f7495df7da3c1384b4657cb9c0054e8a287ebdf71c23b938608b")
if err != nil {
fmt.Printf("Houve falha ao gerar a chave privada: %+v", err)
}
pubkey := pvtkey.Public()
pubkeyECDSA, ok := pubkey.(*ecdsa.PublicKey)
if !ok {
fmt.Printf("Houve falha fazer o casting da chave publica para o padrão ECDSA")
}
origem := crypto.PubkeyToAddress(*pubkeyECDSA)
nonce, err := client.PendingNonceAt(context.Background(), origem)
if err != nil {
fmt.Printf("Houve falha ao gerar o nonce da conta na rede: %+v", err)
}
fmt.Print(origem)
gasPrice, err := client.SuggestGasPrice(context.Background())
if err != nil {
fmt.Printf("Houve falha ao obter o preco sugerido de gas da rede: %+v", err)
}
auth := bind.NewKeyedTransactor(pvtkey)
auth.GasLimit = uint64(30000000)
//
// Increase here the gas price suggested by Ethereum network in order to have your transaction mined faster
//
auth.GasPrice = gasPrice.Mul(gasPrice, big.NewInt(2))
auth.Value = big.NewInt(0)
//
// If you want to resend the transaction with higher gas price do not change the previous nonce number
//
auth.Nonce = big.NewInt(int64(nonce))
key, _ := crypto.GenerateKey()
destinationAccount := bind.NewKeyedTransactor(key)
//Carrega conta da empresa com weis
fmt.Print(destinationAccount.From)
fmt.Print( auth.From)
tx := types.NewTransaction(uint64(auth.Nonce.Int64()), destinationAccount.From, big.NewInt(101000000000000), auth.GasLimit, auth.GasPrice, nil)
signedTx, err := auth.Signer(types.HomesteadSigner{}, auth.From, tx)
if err != nil {
fmt.Printf("Houve falha ao assinar a transação para enviar ether a nova conta de um comprador de registro: %+v", err)
}
client.SendTransaction(context.Background(), signedTx)
}