accounts/abi/abigen: add GetABI() method to abigen v2 generated bindings

Adds a GetABI() accessor to the generated contract struct so callers in
other packages can retrieve the parsed abi.ABI without having to call
ParseABI() themselves. Previously the abi field was unexported and
inaccessible outside the generated package, forcing users to re-parse
the ABI manually.

Fixes #34705
This commit is contained in:
Juan Franco 2026-06-25 23:59:44 -04:00
parent 4387f433c9
commit 08a7d96c65
22 changed files with 110 additions and 0 deletions

View file

@ -59,6 +59,11 @@ var (
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *{{.Type}}) GetABI() abi.ABI {
return c.abi
}
// New{{.Type}} creates a new instance of {{.Type}}.
func New{{.Type}}() *{{.Type}} {
parsed, err := {{.Type}}MetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type CallbackParam struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *CallbackParam) GetABI() abi.ABI {
return c.abi
}
// NewCallbackParam creates a new instance of CallbackParam.
func NewCallbackParam() *CallbackParam {
parsed, err := CallbackParamMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type Crowdsale struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *Crowdsale) GetABI() abi.ABI {
return c.abi
}
// NewCrowdsale creates a new instance of Crowdsale.
func NewCrowdsale() *Crowdsale {
parsed, err := CrowdsaleMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type DAO struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *DAO) GetABI() abi.ABI {
return c.abi
}
// NewDAO creates a new instance of DAO.
func NewDAO() *DAO {
parsed, err := DAOMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type DeeplyNestedArray struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *DeeplyNestedArray) GetABI() abi.ABI {
return c.abi
}
// NewDeeplyNestedArray creates a new instance of DeeplyNestedArray.
func NewDeeplyNestedArray() *DeeplyNestedArray {
parsed, err := DeeplyNestedArrayMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type Empty struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *Empty) GetABI() abi.ABI {
return c.abi
}
// NewEmpty creates a new instance of Empty.
func NewEmpty() *Empty {
parsed, err := EmptyMetaData.ParseABI()

View file

@ -35,6 +35,11 @@ type EventChecker struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *EventChecker) GetABI() abi.ABI {
return c.abi
}
// NewEventChecker creates a new instance of EventChecker.
func NewEventChecker() *EventChecker {
parsed, err := EventCheckerMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type Getter struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *Getter) GetABI() abi.ABI {
return c.abi
}
// NewGetter creates a new instance of Getter.
func NewGetter() *Getter {
parsed, err := GetterMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type IdentifierCollision struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *IdentifierCollision) GetABI() abi.ABI {
return c.abi
}
// NewIdentifierCollision creates a new instance of IdentifierCollision.
func NewIdentifierCollision() *IdentifierCollision {
parsed, err := IdentifierCollisionMetaData.ParseABI()

View file

@ -35,6 +35,11 @@ type InputChecker struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *InputChecker) GetABI() abi.ABI {
return c.abi
}
// NewInputChecker creates a new instance of InputChecker.
func NewInputChecker() *InputChecker {
parsed, err := InputCheckerMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type Interactor struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *Interactor) GetABI() abi.ABI {
return c.abi
}
// NewInteractor creates a new instance of Interactor.
func NewInteractor() *Interactor {
parsed, err := InteractorMetaData.ParseABI()

View file

@ -42,6 +42,11 @@ type NameConflict struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *NameConflict) GetABI() abi.ABI {
return c.abi
}
// NewNameConflict creates a new instance of NameConflict.
func NewNameConflict() *NameConflict {
parsed, err := NameConflictMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type NumericMethodName struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *NumericMethodName) GetABI() abi.ABI {
return c.abi
}
// NewNumericMethodName creates a new instance of NumericMethodName.
func NewNumericMethodName() *NumericMethodName {
parsed, err := NumericMethodNameMetaData.ParseABI()

View file

@ -35,6 +35,11 @@ type OutputChecker struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *OutputChecker) GetABI() abi.ABI {
return c.abi
}
// NewOutputChecker creates a new instance of OutputChecker.
func NewOutputChecker() *OutputChecker {
parsed, err := OutputCheckerMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type Overload struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *Overload) GetABI() abi.ABI {
return c.abi
}
// NewOverload creates a new instance of Overload.
func NewOverload() *Overload {
parsed, err := OverloadMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type RangeKeyword struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *RangeKeyword) GetABI() abi.ABI {
return c.abi
}
// NewRangeKeyword creates a new instance of RangeKeyword.
func NewRangeKeyword() *RangeKeyword {
parsed, err := RangeKeywordMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type Slicer struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *Slicer) GetABI() abi.ABI {
return c.abi
}
// NewSlicer creates a new instance of Slicer.
func NewSlicer() *Slicer {
parsed, err := SlicerMetaData.ParseABI()

View file

@ -41,6 +41,11 @@ type Structs struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *Structs) GetABI() abi.ABI {
return c.abi
}
// NewStructs creates a new instance of Structs.
func NewStructs() *Structs {
parsed, err := StructsMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type Token struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *Token) GetABI() abi.ABI {
return c.abi
}
// NewToken creates a new instance of Token.
func NewToken() *Token {
parsed, err := TokenMetaData.ParseABI()

View file

@ -61,6 +61,11 @@ type Tuple struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *Tuple) GetABI() abi.ABI {
return c.abi
}
// NewTuple creates a new instance of Tuple.
func NewTuple() *Tuple {
parsed, err := TupleMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type Tupler struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *Tupler) GetABI() abi.ABI {
return c.abi
}
// NewTupler creates a new instance of Tupler.
func NewTupler() *Tupler {
parsed, err := TuplerMetaData.ParseABI()

View file

@ -36,6 +36,11 @@ type Underscorer struct {
abi abi.ABI
}
// GetABI returns the ABI associated with this contract binding.
func (c *Underscorer) GetABI() abi.ABI {
return c.abi
}
// NewUnderscorer creates a new instance of Underscorer.
func NewUnderscorer() *Underscorer {
parsed, err := UnderscorerMetaData.ParseABI()