-
Notifications
You must be signed in to change notification settings - Fork 0
/
contract_deploy.go
61 lines (50 loc) · 1.58 KB
/
contract_deploy.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
package main
import (
"context"
"crypto/ecdsa"
"fmt"
"log"
"math/big"
"os"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
store "github.com/marioidival/geth-study/contracts"
)
func main() {
client, err := ethclient.Dial(os.Getenv("RINKEBY_INFURA_URL"))
if err != nil {
log.Fatalf("ethclient connection error: %s", err.Error())
}
privateKey, err := crypto.HexToECDSA("fad9c8855b740a0b7ed4c221dbad0f33a83a49cad6b3fe8d5817ac83d38b6a19")
if err != nil {
log.Fatalf("get private key error: %s", err.Error())
}
publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
log.Fatalf("cannot assert type: publicKey is not of type *ecdsa.PublicKey")
}
fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)
nonce, err := client.PendingNonceAt(context.Background(), fromAddress)
if err != nil {
log.Fatalf("try get pending nonce error: %s", err.Error())
}
gasPrice, err := client.SuggestGasPrice(context.Background())
if err != nil {
log.Fatalf("try get gas price suggestion error: %s", err.Error())
}
auth := bind.NewKeyedTransactor(privateKey)
auth.Nonce = big.NewInt(int64(nonce))
auth.Value = big.NewInt(0)
auth.GasPrice = gasPrice
auth.GasLimit = uint64(300000)
input := "1.0"
address, tx, instance, err := store.DeployStore(auth, client, input)
if err != nil {
log.Fatalf("try do deploy of smart contract error: %s", err.Error())
}
fmt.Println("Address: ", address.Hex())
fmt.Println("Transaction hash", tx.Hash().Hex())
_ = instance
}