【发布时间】:2019-01-28 13:39:06
【问题描述】:
我正在尝试在 go sdk 中部署以太坊智能合约,但我遇到了一些错误
./inbox_test.go:20:44: not enough arguments in call to backends.NewSimulatedBackend
have (core.GenesisAlloc)
want (core.GenesisAlloc, uint64)
我正在按照分步指南在 go 中部署智能合约,但我无法做到这一点
func TestDeployInbox(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(1000000000)}
blockchain := backends.NewSimulatedBackend(alloc)
//Deploy contract
address, _, _, err := DeployInbox(
auth,
blockchain,
"Hello World",
)
// commit all pending transactions
blockchain.Commit()
if err != nil {
t.Fatalf("Failed to deploy the Inbox contract: %v", err)
}
if len(address.Bytes()) == 0 {
t.Error("Expected a valid deployment address. Received empty address byte array instead")
}
}
此代码应在 go sdk 中部署智能合约
【问题讨论】:
-
错误似乎很明显 - 你用一个参数调用
NewSimulatedBackend,它需要两个参数。 -
确实需要两个参数,但我没有得到要传递的第二个参数
-
你从来没有在这里说明你实际使用的是什么包,所以很难猜到,但无论如何我都会推荐阅读它的文档。
标签: go go-ethereum