[英]Getting ERC1155 Wallet Balance Using Java Web3J
Since Web3J doesn't currently support ERC1155, is there a way to get the balance for a wallet?由于 Web3J 目前不支持 ERC1155,有没有办法获得钱包的余额? My guess is to use a function for this, but I can't seem to figure out how to get it to work.我的猜测是为此使用一个函数,但我似乎无法弄清楚如何让它工作。
Function function = new Function(
"balancedOf",
Arrays.asList(new Address(ethAddress), new Uint256(1)),
Arrays.asList(new org.web3j.abi.TypeReference<Bool>() {}));
String data = FunctionEncoder.encode(function);
Do I then create a transaction?然后我要创建交易吗? Or do I use ethSendRawTransaction?还是我使用 ethSendRawTransaction? balanceOf only has 2 input so I would expect to have to invoke it from a smartcontract, but I don't see a way to do it. balanceOf 只有 2 个输入,所以我希望必须从智能合约中调用它,但我看不到这样做的方法。
From reading the web3j docs, It seems that you can do the following:通过阅读 web3j 文档,您似乎可以执行以下操作:
Function function = new Function<>(
"functionName",
Arrays.asList(new Type(value)), // Solidity Types in smart contract functions
Arrays.asList(new TypeReference<Type>() {}, ...));
String encodedFunction = FunctionEncoder.encode(function)
org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
Transaction.createEthCallTransaction(<from>, contractAddress, encodedFunction),
DefaultBlockParameterName.LATEST)
.sendAsync().get();
List<Type> someTypes = FunctionReturnDecoder.decode(
response.getValue(), function.getOutputParameters());
The response
object, from org.web3j.protocol.core.methods.response.EthCall
does the JSON-RPC call "eth_call" which only retrieves data form the blockchain.来自org.web3j.protocol.core.methods.response.EthCall
的response
对象执行 JSON-RPC 调用“eth_call”,它只从区块链中检索数据。
I believe this is the equivalent of doing in web3js the following:我相信这相当于在 web3js 中执行以下操作:
let contract = new web3.eth.Contract(<ABI>, <Contract Address>);
const res = await contract.functionName(<params>);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.