1

尝试使用 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 中的 TypeReference() 不能应用于 (boolean)

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

4

1 回答 1

0

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

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

public static final Event OWNERSHIPRENOUNCED_EVENT = new Event("OwnershipRenounced",
        Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}),
        Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
;
于 2018-08-07T11:20:10.103 回答