1717package bind
1818
1919import (
20+ "errors"
21+
2022 "github.com/ethereum/go-ethereum"
2123 "github.com/ethereum/go-ethereum/accounts/abi"
2224 bind1 "github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -34,7 +36,7 @@ type ContractInstance struct {
3436 abi abi.ABI
3537}
3638
37- func NewContractInstance (addr common.Address , backend ContractBackend , abi abi.ABI ) ContractInstance {
39+ func NewContractInstance (backend ContractBackend , addr common.Address , abi abi.ABI ) ContractInstance {
3840 return ContractInstance {addr , backend , abi }
3941}
4042
@@ -169,8 +171,11 @@ func Transact(instance ContractInstance, opts *TransactOpts, input []byte) (*typ
169171 return c .RawTransact (opts , input )
170172}
171173
172- // Call performs an eth_call on the given bound contract instance, using the
173- // provided abi-encoded input (or nil).
174+ // Call performs an eth_call on the given bound contract instance, using the provided
175+ // ABI-encoded input.
176+ //
177+ // To call a function that doesn't return any output, pass nil as the unpack function.
178+ // This can be useful if you just want to check that the function doesn't revert.
174179func Call [T any ](instance ContractInstance , opts * CallOpts , packedInput []byte , unpack func ([]byte ) (T , error )) (T , error ) {
175180 var defaultResult T
176181 backend := instance .Backend
@@ -179,6 +184,12 @@ func Call[T any](instance ContractInstance, opts *CallOpts, packedInput []byte,
179184 if err != nil {
180185 return defaultResult , err
181186 }
187+ if unpack == nil {
188+ if len (packedOutput ) > 0 {
189+ return defaultResult , errors .New ("contract returned data, but no unpack function was given" )
190+ }
191+ return defaultResult , nil
192+ }
182193 res , err := unpack (packedOutput )
183194 if err != nil {
184195 return defaultResult , err
0 commit comments