Me gustaría preguntar cómo enviar correctamente el token ERC20 de una billetera a otra billetera, los siguientes son mis códigos:
public static void main(String[] args) throws Exception {
Web3j web3 = Web3j.build(new HttpService()); // defaults to http://localhost:8545/
Web3ClientVersion web3ClientVersion = web3.web3ClientVersion().send();
String clientVersion = web3ClientVersion.getWeb3ClientVersion();
Credentials creds = WalletUtils.loadCredentials("password",
"path/to/wallet");
EthGetBalance ethGetBalance = web3.ethGetBalance(creds.getAddress(), DefaultBlockParameterName.LATEST)
.sendAsync().get();
BigInteger wei = ethGetBalance.getBalance();
FixedSupplyToken_sol_FixedSupplyToken contract = FixedSupplyToken_sol_FixedSupplyToken
.load("0x<CONTRACT_ADDRESS>", web3, creds, gasPrice, gasLimit);
BigInteger tokenAmount = contract.balanceOf(creds.getAddress()).send();
contract.transfer("0x<TO_ADDRESS>", new BigInteger("10000")).send();
}
Cuando traté de ejecutar este código, funciona, la transacción se envía a mi red privada, pero devuelve estos errores.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.web3j.protocol.exceptions.TransactionException: Error processing request: unknown transaction
at org.web3j.tx.response.TransactionReceiptProcessor.sendTransactionReceiptRequest(TransactionReceiptProcessor.java:32)
at org.web3j.tx.response.PollingTransactionReceiptProcessor.getTransactionReceipt(PollingTransactionReceiptProcessor.java:37)
at org.web3j.tx.response.PollingTransactionReceiptProcessor.waitForTransactionReceipt(PollingTransactionReceiptProcessor.java:29)
at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:72)
at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:51)
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:70)
at org.web3j.tx.Contract.executeTransaction(Contract.java:223)
at org.web3j.tx.Contract.executeTransaction(Contract.java:207)
at org.web3j.tx.Contract.executeTransaction(Contract.java:201)
at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:240)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
at com.gio.myapp.App.main(App.java:50)
¿Hay algo que me perdí aquí?
Puede codificar manualmente los datos con la función:
public static String encodeTransferData(String toAddress, BigInteger sum) {
Function function = new Function(
"transfer", // function we're calling
Arrays.asList(new Address(toAddress), new Uint256(sum)), // Parameters to pass as Solidity Types
Arrays.asList(new org.web3j.abi.TypeReference<Bool>() {}));
return FunctionEncoder.encode(function);
}
y llamar al contrato de esta manera:
public static void main(String[] args) throws Exception {
Web3j web3 = Web3j.build(new HttpService()); // defaults to http://localhost:8545/
Credentials creds = WalletUtils.loadCredentials("password", "path/to/wallet");
RawTransactionManager manager = new RawTransactionManager(web3, creds);
String toAddress = "0x..."; // destination address
String contractAddress = "0x...";
BigInteger sum = BigInteger.valueOf(10000); // amount you want to send
String data = encodeTransferData(toAddress, sum);
BigInteger gasPrice = web3.ethGasPrice().send().getGasPrice();
BigInteger gasLimit = BigInteger.valueOf(120000); // set gas limit here
EthSendTransaction transaction = manager.sendTransaction(gasPrice, gasLimit, contractAddress, data, null);
}
Esto tiene que ver con el hash de la transacción que no se encuentra en la cadena de bloques.
Intente, por ejemplo, generar el hash de transacción como una cadena después de la transacción.
También intente reemplazar la línea
contract.transfer("0x<TO_ADDRESS>", new BigInteger("10000")).send();
con
contract.transfer("0x<TO_ADDRESS>", new BigInteger("10000")).sendAsync().get();
puede ayudarle a localizar el problema de forma más explícita o incluso a resolverlo.
TransactionReceipt tr = contract.transfer("0x80daA7E15FE9D96CC5dfdC1d61009d3108eb6ED4", new BigInteger("10000")).sendAsync().get(); String hash = tr.getTransactionHash();
Intenté cambiar el código y convertirlo en el código anterior, sin suerte, ocurre el mismo error
david preradovic
ivicaa