"transaction type not supported" When trying to deploy a simple contract using Go-Ethereum, Solidity, Go. Doesn't happen in Remix

huangapple go评论104阅读模式
英文:

"transaction type not supported" When trying to deploy a simple contract using Go-Ethereum, Solidity, Go. Doesn't happen in Remix

问题

每当我尝试将我的智能合约部署到测试环境时,都会收到一个错误,指示“不支持的交易类型”。以下是源代码。我正在尝试使用abigen的Go绑定部署我的简单智能合约。

版本:
go1.16.7
Solidity 0.8.9+commit.e5eed63a.Darwin.appleclang

Solidity源代码。我在Remix中测试过,每次都成功:

contract SendMSG {
    function Send(address sendTo, bytes calldata message) public {
        OtherContract other = OtherContract(sendTo);
        other.send(message);
    }
}

这是我使用的合约,请忽略语法错误,因为这可能是匿名化时的人为错误。

然后我运行以下命令来生成abi绑定并将其放在正确的位置。我可以确认这个命令是有效的,因为go文件总是会被创建:
abigen --sol ../../contracts/Contract.sol --pkg Contract --out Contract.go

Go代码。我认为不应该有任何问题。我正在使用模拟的后端/区块链进行测试:

package Contract
import (
	"testing"
	"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
	"github.com/ethereum/go-ethereum/accounts/abi/bind"
	"github.com/ethereum/go-ethereum/crypto"
	"github.com/ethereum/go-ethereum/core"
	"github.com/ethereum/go-ethereum/common"
	"math/big"
)

// 测试正确部署inbox合约
func TestMain(t *testing.T) {

	// 设置模拟的区块链
	key, _ := crypto.GenerateKey()
	auth := bind.NewKeyedTransactor(key)

	alloc := make(core.GenesisAlloc)
	alloc[auth.From] = core.GenesisAccount{Balance: big.NewInt(133700000)}
	gasLimit := 300000
	sim := backends.NewSimulatedBackend(alloc, gasLimit)

	
	// 部署合约
	address, _, _, err := DeploySameBindings(
		auth,
		sim,

	)
	// 提交所有待处理的交易
	blockchain.Commit()
	
	if err != nil {
		t.Fatalf("无法部署合约:%v", err)
	}
}

每次都会出现相同的错误,"transaction type not supported"。我知道错误的来源在这一行[GitHub]。从那里开始,也许我没有设置支付机制?但是我看过的所有教程都没有包括这一点,如果有人能提供关于如何设置支付机制的指南,我将不胜感激。

谢谢。

英文:

When ever I try to deploy my smart contract to test, I receive an error indicating "transaction type not supported". Below is the source code. I'm trying to deploy my simple smart contract using abigen's Go bindings.

Versions:
go1.16.7
Solidity 0.8.9+commit.e5eed63a.Darwin.appleclang

Solidity Source code. I've tested this in Remix and it has worked everytime:

contract SendMSG {
    function Send(address sendTo, bytes calldata message) public {
        OtherContract other = OtherContract(sendTo);
        other.send(message);
    }
}

This is the contract I'm using ignore syntax errors as it may be human error while anonymizing.

I then run this line to develop the abi bindings and put them in the right place. I can confirm this works as the go file is always created:
abigen --sol ../../contracts/Contract.sol --pkg Contract --out Contract.go

Go Code. I believe there shouldn't be any issues. I'm using a simulated backend/blockchain for testing:

package Contract
import (
	"testing"
	"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
	"github.com/ethereum/go-ethereum/accounts/abi/bind"
	"github.com/ethereum/go-ethereum/crypto"
	"github.com/ethereum/go-ethereum/core"
	"github.com/ethereum/go-ethereum/common"
	"math/big"
)

// Test inbox contract gets deployed correctly
func TestMain(t *testing.T) {

	//Setup simulated block chain
	key, _ := crypto.GenerateKey()
	auth := bind.NewKeyedTransactor(key)

	alloc := make(core.GenesisAlloc)
	alloc[auth.From] = core.GenesisAccount{Balance: big.NewInt(133700000)}
	gasLimit := 300000
	sim := backends.NewSimulatedBackend(alloc, gasLimit)

	
	//Deploy contract
	address, _, _, err := DeploySameBindings(
		auth,
		sim,

	)
	// commit all pending transactions
	blockchain.Commit()
	
	if err != nil {
		t.Fatalf("Failed to deploy the contract: %v", err)
	}
}

Always, it gives the same err, "transaction type not supported". I know the line where the error origin [GitHub]. From there, maybe I didn't set a payment mechanism? But all the tutorials I've seen didn't include one and if anyone could provide a guide as to how to do that.

Thank you.

答案1

得分: 1

这是愚蠢的。

Geth更新了他们的代码,没有任何教程,所以对于希望运行模拟后台的人来说,这是答案:

你必须手动设置gas价格。在定义了client和auth之后,采取以下步骤可以解决这个问题。

gasPrice, err := client.SuggestGasPrice(context.Background())
auth.GasPrice = gasPrice
英文:

This was stupid.

Geth updated their code and there weren't any tutorials so for anyone hoping to run a simulated background here's the answer:

You have to set the gas price manually. Taking this on after defining client and auth fixes it.

gasPrice, err := client.SuggestGasPrice(context.Background())
auth.GasPrice=gasPrice

huangapple
  • 本文由 发表于 2021年11月12日 04:41:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/69934685.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定