forked from flare-foundation/developer-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy_contract.go
46 lines (41 loc) · 1.18 KB
/
deploy_contract.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
// THIS IS EXAMPLE CODE. DO NOT USE THIS CODE IN PRODUCTION.
package flare
import (
"context"
"fmt"
"strings"
"time"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/ethclient"
)
// Paste the contents of the generated keystore file here
// DO NOT USE THIS CODE IN PRODUCTION.
// NEVER COMMIT PRIVATE KEYS TO A GIT REPOSITORY.
const key = ``
func DeployContract() {
conn, err := ethclient.Dial("https://flare-api.flare.network/ext/C/rpc")
if err != nil {
panic(err)
}
ctx := context.Background()
chainId, err := conn.ChainID(ctx)
if err != nil {
panic(err)
}
auth, err := bind.NewTransactorWithChainID(strings.NewReader(key), "Creation password", chainId)
if err != nil {
panic(err)
}
address, tx, ftsoV2FeedConsumer, err := DeployFtsoV2FeedConsumer(auth, conn)
if err != nil {
panic(err)
}
fmt.Printf("Contract pending deploy: 0x%x\n", address)
fmt.Printf("Transaction waiting to be mined: 0x%x\n\n", tx.Hash())
time.Sleep(2000 * time.Millisecond)
feeds, err := ftsoV2FeedConsumer.GetFtsoV2CurrentFeedValues(&bind.CallOpts{Context: ctx, Pending: true})
if err != nil {
panic(err)
}
fmt.Println("Feeds values and decimals:", feeds)
}