### 前言 这是这个的最后一期,因为电子书后面的内容暂时没有什么必要学了,接下来会编写solc笔记和其他。 拜拜了您内。 --- ### 部署智能合约 ``` client, _ := ethclient.Dial("http://127.0.0.1:8545") // 设定私钥和燃气费 private, _ := crypto.HexToECDSA("bd380efe66a9ff36d66d4ab20b76e79de62ecc745b3f31362d421bee33dc0446") // publicKey := private.Public() // public := publicKey.(*ecdsa.PublicKey) // NewKeyedTransactor在新版变成了 NewKeyedTransactorWithChainID ChanID, _ := client.NetworkID(context.Background()) auto, _ := bind.NewKeyedTransactorWithChainID(private, ChanID) auto.Nonce = big.NewInt(300) auto.Value = big.NewInt(0) auto.GasLimit = 300 auto.GasPrice, _ = client.SuggestGasPrice(context.Background()) // 加载智能合约 address, tx, instance, _ := store.DeployStore(auto, client, "1.0") logrus.Info("solc address :", address) logrus.Info("expen:", tx, "instance:", instance) ``` 需要注意的是: ``` NewKeyedTransactor在新版变成了 NewKeyedTransactorWithChainID ``` 这里因为框架代码已经放弃了这个方法。 --- ### 加载合约 ``` client, _ := ethclient.Dial("http://127.0.0.1:8545") // 加载地址 address := common.HexToAddress("0x4ad02236A1229029b013838FE0A5e44d349828c9") instance, _ := store.NewStore(address, client) logrus.Info(instance.StoreCaller) // 查询智能合约 logrus.Info(instance.Version(nil)) ``` --- 没什么坑。 Loading... ### 前言 这是这个的最后一期,因为电子书后面的内容暂时没有什么必要学了,接下来会编写solc笔记和其他。 拜拜了您内。 --- ### 部署智能合约 ``` client, _ := ethclient.Dial("http://127.0.0.1:8545") // 设定私钥和燃气费 private, _ := crypto.HexToECDSA("bd380efe66a9ff36d66d4ab20b76e79de62ecc745b3f31362d421bee33dc0446") // publicKey := private.Public() // public := publicKey.(*ecdsa.PublicKey) // NewKeyedTransactor在新版变成了 NewKeyedTransactorWithChainID ChanID, _ := client.NetworkID(context.Background()) auto, _ := bind.NewKeyedTransactorWithChainID(private, ChanID) auto.Nonce = big.NewInt(300) auto.Value = big.NewInt(0) auto.GasLimit = 300 auto.GasPrice, _ = client.SuggestGasPrice(context.Background()) // 加载智能合约 address, tx, instance, _ := store.DeployStore(auto, client, "1.0") logrus.Info("solc address :", address) logrus.Info("expen:", tx, "instance:", instance) ``` 需要注意的是: ``` NewKeyedTransactor在新版变成了 NewKeyedTransactorWithChainID ``` 这里因为框架代码已经放弃了这个方法。 --- ### 加载合约 ``` client, _ := ethclient.Dial("http://127.0.0.1:8545") // 加载地址 address := common.HexToAddress("0x4ad02236A1229029b013838FE0A5e44d349828c9") instance, _ := store.NewStore(address, client) logrus.Info(instance.StoreCaller) // 查询智能合约 logrus.Info(instance.Version(nil)) ``` --- 没什么坑。 最后修改:2023 年 03 月 26 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏