From 2241fbb5f489f03175b1f5063e9319e3242425f5 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Thu, 6 Feb 2025 15:02:14 -0800 Subject: [PATCH] accounts/abi/bind/v2: add Transact utility method for v2. There is already an identical Transact member method on the BoundContract struct. I just add this one to ensure that user code which performs transactions doesn't have to use both the v1 BoundContract methods and the utility methods provided in v2/lib.go --- accounts/abi/bind/v2/lib.go | 6 ++++++ accounts/abi/bind/v2/lib_test.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/accounts/abi/bind/v2/lib.go b/accounts/abi/bind/v2/lib.go index c9c4da5547..4e9f559e58 100644 --- a/accounts/abi/bind/v2/lib.go +++ b/accounts/abi/bind/v2/lib.go @@ -175,6 +175,12 @@ func Call[T any](c *BoundContract, opts *CallOpts, packedInput []byte, unpack fu return res, err } +// Transact initiates a transaction with the given raw calldata as the input. +func Transact(c *BoundContract, opt *TransactOpts, packedInput []byte) (*types.Transaction, error) { + addr := c.address + return c.transact(opt, &addr, packedInput) +} + // DeployContract deploys a contract onto the Ethereum blockchain and binds the // deployment address with a Go wrapper. It expects its parameters to be abi-encoded // bytes. diff --git a/accounts/abi/bind/v2/lib_test.go b/accounts/abi/bind/v2/lib_test.go index 295b718ed1..5cbc0374b5 100644 --- a/accounts/abi/bind/v2/lib_test.go +++ b/accounts/abi/bind/v2/lib_test.go @@ -236,7 +236,7 @@ func TestEvents(t *testing.T) { defer sub2.Unsubscribe() packedInput := c.PackEmitMulti() - tx, err := instance.RawTransact(defaultTxAuth(), packedInput) + tx, err := bind.Transact(instance, defaultTxAuth(), packedInput) if err != nil { t.Fatalf("failed to send transaction: %v", err) }