-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontract_deploy.go
49 lines (46 loc) · 1.15 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
package main
import (
"context"
"crypto/ecdsa"
"fmt"
"math/big"
"os"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
)
func main() {
client, err := ethclient.Dial("https://goerli.infura.io/v3/c313f9648c3742528bae0c24717d45aa")
if err != nil {
return
}
privateKey, err := crypto.HexToECDSA(os.Getenv("WALLET_PRIVATE_KEY"))
if err != nil {
return
}
publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
return
}
fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)
nonce, err := client.PendingNonceAt(context.Background(), fromAddress)
if err != nil {
return
}
gasPrice, err := client.SuggestGasPrice(context.Background())
if err != nil {
return
}
auth := bind.NewKeyedTransactor(privateKey)
auth.Nonce = big.NewInt(int64(nonce))
auth.Value = big.NewInt(0)
auth.GasLimit = uint64(6000000)
auth.GasPrice = gasPrice
address, tx, _, err := DeployAccessControlIPFS(auth, client)
if err != nil {
return
}
fmt.Println("Contract Address: ", address.Hex())
fmt.Println("Transaction:", tx.Hash().Hex())
}