设置代码:
package main
// 签名用的公钥私钥也是采用的owner的公钥私钥
import (
"fmt"
"set_signer/triplec"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
)
const (
BETA_SERVER_ADDRESS = "https://data-seed-prebsc-1-s1.bnbchain.org:8545"
BETA_CONTRACT_ADDRESS = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
BETA_CONTRACT_OWNER_PUBLIC_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
BETA_CONTRACT_OWNER_PRIVATE_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
func GetConfig() (string, string, string, string) {
// 默认返回 beta 配置
return BETA_SERVER_ADDRESS, BETA_CONTRACT_ADDRESS, BETA_CONTRACT_OWNER_PUBLIC_KEY, BETA_CONTRACT_OWNER_PRIVATE_KEY
}
func main() {
serverAddress, contractAddress, ownerPublicKey, ownerPrivateKey := GetConfig()
client, _ := ethclient.Dial(serverAddress)
privateKey, err := crypto.HexToECDSA(ownerPrivateKey)
if err != nil {
panic(err)
}
auth, err := Author(privateKey, client, 500000, 0)
medal, err := triplec.NewTriplec(common.HexToAddress(contractAddress), client)
// 设置signer,为signPrev对应的公钥
tx, err := medal.SetSinger(auth, common.HexToAddress(ownerPublicKey))
if err != nil {
panic("error")
}
if tx == nil {
panic("error")
}
hash := tx.Hash().Hex()
fmt.Printf("setsigner 的hash:%v", hash)
}
结果:
成功与否说明:
有了hash不表示就一定是设置成功了!
设置成功的标志是对应网络的scan能够正常查询到该hash
bsc测试网络:https://data-seed-prebsc-1-s1.bnbchain.org:8545对应的scan是https://testnet.bscscan.com/
标签:hash,err,CONTRACT,signer,BETA,ethereum,go From: https://www.cnblogs.com/zhanchenjin/p/17740483.html