File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -272,8 +272,24 @@ func (c *BoundContract) RawCreationTransact(opts *TransactOpts, calldata []byte)
272
272
// Transfer initiates a plain transaction to move funds to the contract, calling
273
273
// its default method if one is available.
274
274
func (c * BoundContract ) Transfer (opts * TransactOpts ) (* types.Transaction , error ) {
275
- // todo(rjl493456442) check the payable fallback or receive is defined
276
- // or not, reject invalid transaction at the first place
275
+ // Check if payable fallback or receive is defined
276
+ hasPayable := false
277
+ for _ , method := range c .abi .Methods {
278
+ // In ABI, receive and fallback are special
279
+ if method .Name == "" && method .Type == abi .Fallback && method .Payable {
280
+ hasPayable = true
281
+ break
282
+ }
283
+ if method .Type == abi .Receive && method .Payable {
284
+ hasPayable = true
285
+ break
286
+ }
287
+ }
288
+
289
+ if ! hasPayable {
290
+ return nil , fmt .Errorf ("contract does not have a payable fallback or receive function" )
291
+ }
292
+
277
293
return c .transact (opts , & c .address , nil )
278
294
}
279
295
You can’t perform that action at this time.
0 commit comments