java [SDK] <Title> #235
-
EnvironmentMainnet Acknowledgement
Issue DescriptionBigInteger nonce = zksync
.ethGetTransactionCount(signer.getAddress(), ZkBlockParameterName.COMMITTED).send()
.getTransactionCount(); This part of the code in the document will report an Invalid response received: 400; error, but changing the parameter to ZkBlockParameterName.FINALIZED will not report an error. Expected BehaviorI want to get the committed noce I need it Code Exampleimport io.zksync.abi.TransactionEncoder;
import io.zksync.crypto.signer.EthSigner;
import io.zksync.methods.request.Transaction;
import io.zksync.protocol.ZkSync;
import io.zksync.protocol.core.Token;
import io.zksync.protocol.core.ZkBlockParameterName;
import io.zksync.transaction.fee.DefaultTransactionFeeProvider;
import io.zksync.transaction.fee.ZkTransactionFeeProvider;
import io.zksync.transaction.type.Transaction712;
import io.zksync.transaction.response.ZkSyncTransactionReceiptProcessor;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.core.methods.response.EthSendTransaction;
import org.web3j.protocol.exceptions.TransactionException;
import org.web3j.utils.Convert;
import org.web3j.utils.Numeric;
import java.io.IOException;
import java.math.BigInteger;
import static io.zksync.transaction.manager.ZkSyncTransactionManager.DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH;
import static io.zksync.transaction.manager.ZkSyncTransactionManager.DEFAULT_POLLING_FREQUENCY;
public class Main {
public static void main(String ...args) throws IOException, TransactionException {
ZkSync zksync; // Initialize client
EthSigner signer; // Initialize signer
ZkSyncTransactionReceiptProcessor processor = new ZkSyncTransactionReceiptProcessor(zksync, DEFAULT_POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH);
BigInteger chainId = zksync.ethChainId().send().getChainId();
BigInteger amountInWei = Convert.toWei("1", Convert.Unit.ETHER).toBigInteger();
BigInteger nonce = zksync
.ethGetTransactionCount(signer.getAddress(), ZkBlockParameterName.COMMITTED).send()
.getTransactionCount();
Transaction estimate = Transaction.createFunctionCallTransaction(
signer.getAddress(),
"0x<receiver_address>",
BigInteger.ZERO,
BigInteger.ZERO,
amountInWei,
"0x"
);
ZkTransactionFeeProvider feeProvider = new DefaultTransactionFeeProvider(zksync, Token.ETH);
Transaction712 transaction = new Transaction712(
chainId.longValue(),
nonce,
feeProvider.getGasLimit(estimate),
estimate.getTo(),
estimate.getValueNumber(),
estimate.getData(),
BigInteger.valueOf(100000000L),
feeProvider.getGasPrice(),
signer.getAddress(),
estimate.getEip712Meta()
);
String signature = signer.getDomain().thenCompose(domain -> signer.signTypedData(domain, transaction)).join();
byte[] message = TransactionEncoder.encode(transaction, TransactionEncoder.getSignatureData(signature));
EthSendTransaction sent = zksync.ethSendRawTransaction(Numeric.toHexString(message)).send();
TransactionReceipt receipt = processor.waitForTransactionReceipt(sent.getResult());
}
} Repo Link (Optional)No response |
Beta Was this translation helpful? Give feedback.
Answered by
petarTxFusion
Dec 13, 2023
Replies: 6 comments
-
We have tested on: mainnet, testnet and local. We did not manage to reproduce this issue. Is there any additional info which you could share with us? With this code on mainnet we get nonce 25 BigInteger nonce = zksync
.ethGetTransactionCount("0x36615Cf349d7F6344891B1e7CA7C72883F5dc049", ZkBlockParameterName.COMMITTED).send()
.getTransactionCount(); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
MexicanAce
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We have tested on: mainnet, testnet and local. We did not manage to reproduce this issue. Is there any additional info which you could share with us?
With this code on mainnet we get nonce 25