17
17
package bind
18
18
19
19
import (
20
+ "errors"
21
+
20
22
"github.com/ethereum/go-ethereum"
21
23
"github.com/ethereum/go-ethereum/accounts/abi"
22
24
bind1 "github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -34,7 +36,7 @@ type ContractInstance struct {
34
36
abi abi.ABI
35
37
}
36
38
37
- func NewContractInstance (addr common.Address , backend ContractBackend , abi abi.ABI ) ContractInstance {
39
+ func NewContractInstance (backend ContractBackend , addr common.Address , abi abi.ABI ) ContractInstance {
38
40
return ContractInstance {addr , backend , abi }
39
41
}
40
42
@@ -169,8 +171,11 @@ func Transact(instance ContractInstance, opts *TransactOpts, input []byte) (*typ
169
171
return c .RawTransact (opts , input )
170
172
}
171
173
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.
174
179
func Call [T any ](instance ContractInstance , opts * CallOpts , packedInput []byte , unpack func ([]byte ) (T , error )) (T , error ) {
175
180
var defaultResult T
176
181
backend := instance .Backend
@@ -179,6 +184,12 @@ func Call[T any](instance ContractInstance, opts *CallOpts, packedInput []byte,
179
184
if err != nil {
180
185
return defaultResult , err
181
186
}
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
+ }
182
193
res , err := unpack (packedOutput )
183
194
if err != nil {
184
195
return defaultResult , err
0 commit comments