package main
import (
"flag"
"fmt"
"log"
"github.com/FISCO-BCOS/go-sdk/client"
"github.com/FISCO-BCOS/go-sdk/conf"
"github.com/ethereum/go-ethereum/common"
)
func main() {
var nodeURL string
var address string
flag.StringVar(&nodeURL,"u","127.0.0.1:20200","node URL and port")
flag.StringVar(&address,"a","","contract address")
flag.Parse()
if len(address) <= 0{
log.Fatal("contract address is required.")
}
configs, err := conf.ParseConfigFile("conf/config.toml")
if err != nil {
log.Fatal(err)
}
config := &configs[0]
config.NodeURL = nodeURL
client, err := client.Dial(config)
if err != nil {
log.Fatal(err)
}
contractAddress := common.HexToAddress(address)
instance, err := NewHelloWorld(contractAddress, client)
if err != nil {
log.Fatal(err)
}
helloworldSession := &HelloWorldSession{Contract: instance, CallOpts: *client.GetCallOpts(), TransactOpts: *client.GetTransactOpts()}
value := "Hello, FISCO BCOS"
_, receipt, err := helloworldSession.Set(value)
if err != nil {
log.Fatal(err)
}
fmt.Print("nodeurl ",config.NodeURL, " transactionhash ", receipt.GetTransactionHash())
}

- 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
该程序接收2个参数。第1个参数是节点的IP地址和channel端口,将其参数化,便可任意指定要连接的节点。第2个参数是智能合约的地址,可以在FISCO控制台获取。
