一、获取合约abi
粘贴至go项目目录下的abi文件中
合约代码改动,abi也是需要更换的
二、使用abigen工具生成go文件
abigen --abi xx.abi --pkg PackageName --type StructName --out xx.go
- abi 文件在 remix 编译时可以得到
- pkg 指定输出文件的包名,也就是上一级目录名称
- type 指定合约结构体名称
- out 指定输出go文件名称
使用后会生成一个go文件,里面有合约方法
三、调用智能合约
package config
import (
"Sharing/Agreement"
"context"
"crypto/ecdsa"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethc