gpt4 book ai didi

java - Web3j Android java Solidity 包装器错误

转载 作者:太空宇宙 更新时间:2023-11-04 10:17:13 24 4
gpt4 key购买 nike

尝试使用web3j调用合约中的一些函数。我遵循了 Solidity 指南并获得了该合约的 .abi 和 .bin - https://etherscan.io/address/0x9dda40dabd849bbb087dcbcf0c5223ec5ffa0ad7#code 。然后使用web3j命令行对.java文件进行包装,输出到正确的目录。

一切正常,但这些行:

public static final Event FUNDSWITHDRAWN_EVENT = new Event("FundsWithdrawn",
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Uint256>() {}));
;

public static final Event FUNDSDEPOSITED_EVENT = new Event("FundsDeposited",
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Uint256>() {}));
;

public static final Event SERVERADDED_EVENT = new Event("ServerAdded",
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
;

public static final Event SERVERREMOVED_EVENT = new Event("ServerRemoved",
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
;

public static final Event GAMESTARTED_EVENT = new Event("GameStarted",
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<DynamicArray<Address>>() {}));
;

public static final Event GAMEENDED_EVENT = new Event("GameEnded",
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}, new TypeReference<Address>() {}, new TypeReference<Address>() {}, new TypeReference<Address>() {}));
;

抛出错误:

Event() in Event cannot be applied to:
Expected Parameters:
Actual Arguments:

name:
String
"ServerAdded"
indexedParameters:
List<TypeReference<?>>
Arrays...new TypeReference<Uint256>() {})
nonIndexedParameters:
List<TypeReference<?>>

这两行:

    public static final Event OWNERSHIPRENOUNCED_EVENT = new Event("OwnershipRenounced",
Arrays.<TypeReference<?>>asList(new TypeReference<Address>(true) {}));
;

public static final Event OWNERSHIPTRANSFERRED_EVENT = new Event("OwnershipTransferred",
Arrays.<TypeReference<?>>asList(new TypeReference<Address>(true) {}, new TypeReference<Address>(true) {}));
;

报错: 类型引用( ) 在 TypeReference 中无法应用 到 ( boolean 值)

我不是合约创建者,但它在 web3js 和元掩码实现中确实可以正常工作。我在想一件事,因为这些事件是针对服务器端的,我是否需要包含它们? (尽管您可以看到它们稍后会被引用)但我只是想知道使用 .bin 文件是否会迫使您不进行更改?无论如何,这是新手,所以任何帮助或指导表示赞赏,谢谢。

最佳答案

这发生在我身上,似乎是版本问题,因为 Java 类的生成有语法错误。

您所能做的就是尝试手动修复问题:删除 true,并更改一些代码。

public static final Event OWNERSHIPRENOUNCED_EVENT = new Event("OwnershipRenounced",
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}),
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
;

关于java - Web3j Android java Solidity 包装器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51567247/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com