Skip to content

Commit d330916

Browse files
committed
accounts/abi/bind: update v2 template
Two changes: New function doesn't return error anymore. It's annoying having to handle an error there, especially since we know the ABI must be valid (we parsed it in order to generate the contract). The new Instance method returns the ContractInstance for use with v2 library functions.
1 parent 1bdc820 commit d330916

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

accounts/abi/bind/source2.go.tpl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"errors"
99

1010
"github.com/ethereum/go-ethereum/accounts/abi"
11-
"github.com/ethereum/go-ethereum/accounts/abi/bind"
11+
"github.com/ethereum/go-ethereum/accounts/abi/bind/v2"
1212
"github.com/ethereum/go-ethereum/common"
1313
"github.com/ethereum/go-ethereum/core/types"
1414
)
@@ -17,7 +17,6 @@ import (
1717
var (
1818
_ = errors.New
1919
_ = big.NewInt
20-
_ = bind.Bind
2120
_ = common.Big1
2221
_ = types.BloomLookup
2322
_ = abi.ConvertType
@@ -55,14 +54,20 @@ var (
5554
}
5655

5756
// New{{.Type}} creates a new instance of {{.Type}}.
58-
func New{{.Type}}() (*{{.Type}}, error) {
57+
func New{{.Type}}() *{{.Type}} {
5958
parsed, err := {{.Type}}MetaData.GetAbi()
6059
if err != nil {
61-
return nil, err
60+
panic(errors.New("invalid ABI: " + err.Error()))
6261
}
63-
return &{{.Type}}{abi: *parsed}, nil
62+
return &{{.Type}}{abi: *parsed}
6463
}
6564

65+
// Instance creates a wrapper for a deployed contract instance at the given address.
66+
// Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc.
67+
func (c *{{.Type}}) Instance(backend bind.ContractBackend, addr common.Address) bind.ContractInstance {
68+
return bind.NewContractInstance(backend, addr, c.abi)
69+
}
70+
6671
{{ if .Constructor.Inputs }}
6772
func ({{ decapitalise $contract.Type}} *{{$contract.Type}}) PackConstructor({{range .Constructor.Inputs}} {{.Name}} {{bindtype .Type $structs}}, {{end}}) []byte {
6873
res, _ := {{ decapitalise $contract.Type}}.abi.Pack("" {{range .Constructor.Inputs}}, {{.Name}}{{end}})

0 commit comments

Comments
 (0)