Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abigen error: Failed to generate ABI binding in Golang #25252

Closed
bglmmz opened this issue Jul 6, 2022 · 3 comments · Fixed by #25307
Closed

abigen error: Failed to generate ABI binding in Golang #25252

bglmmz opened this issue Jul 6, 2022 · 3 comments · Fixed by #25307
Assignees
Labels

Comments

@bglmmz
Copy link

bglmmz commented Jul 6, 2022

System information

Geth version: v.1.10.20
OS & Version: ubuntu 20.04
Commit hash :
Golang version: 1.17.11
solc version: 0.8.13
solidity version: 0.8.0

Attached zip is my contract source file written in solidiy, and its abi / bin file generated by solc,

then I run this command to generate ABI binding in Golang

./abigen --abi=Vote.abi --bin=Vote.bin --pkg=contracts --type=vote --out=vote.go

but the experted file vote.go has not been generated, and the console printed this message:

Fatal: Failed to generate ABI binding: 465:76: expected ), found 'range' (and 10 more errors)

// Code generated - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.

package contracts

import (
	"math/big"
	"strings"
	"errors"

	ethereum "github.com/ethereum/go-ethereum"
	"github.com/ethereum/go-ethereum/accounts/abi"
	"github.com/ethereum/go-ethereum/accounts/abi/bind"
	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/core/types"
	"github.com/ethereum/go-ethereum/event"
)

// Reference imports to suppress errors if they are not otherwise used.
var (
	_ = errors.New
	_ = big.NewInt
	_ = strings.NewReader
	_ = ethereum.NotFound
	_ = bind.Bind
	_ = common.Big1
	_ = types.BloomLookup
	_ = event.NewSubscription
)
// and more output ......

but it is ok to generate ABI binding in Java with same abi/bin files.

Steps to reproduce the behaviour

extract the attached zip into github.com/go-ethereum/build/bin, and run:

./abigen --abi=Vote.abi --bin=Vote.bin --pkg=contracts --type=vote --out=vote.go

Vote.zip

@bglmmz bglmmz added the type:bug label Jul 6, 2022
@bglmmz
Copy link
Author

bglmmz commented Jul 6, 2022

The contract works on test chain.

@gballet
Copy link
Member

gballet commented Jul 7, 2022

ok, this is a bug indeed: you are using range as a parameter name, and go will recognize it as its range keyword. We have to somehow escape that name. In the mean time, you can just change range to e.g. rnge in your ABI file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@gballet @bglmmz and others