Commit 28012cd9 authored by duanjinfei's avatar duanjinfei

add params chainId

parent bc470641
......@@ -66,7 +66,7 @@ public class SignAndSubmit {
}
}
private byte[] offlineSign(String fromPk, String toAddress, BigInteger value) {
private byte[] offlineSign(String fromPk, String toAddress, BigInteger value,long chainId) {
try {
BigInteger nonce = getAddressNonce(fromPk);
System.out.println("Nonce:" + nonce);
......@@ -84,14 +84,14 @@ public class SignAndSubmit {
value,
"");
System.out.println("toAddress:" + toAddress);
return TransactionEncoder.signMessage(rawTransaction, 512512, credentials);
return TransactionEncoder.signMessage(rawTransaction, chainId, credentials);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public boolean signAndSend(String fromPk, String toAddress, BigInteger value) {
public boolean signAndSend(String fromPk, String toAddress, BigInteger value,long chainId) {
try {
BigInteger nonce = getAddressNonce(fromPk);
System.out.println("Nonce:" + nonce);
......@@ -100,7 +100,7 @@ public class SignAndSubmit {
Credentials credentials = Credentials.create(fromPk);
RawTransactionManager transactionManager = new RawTransactionManager(web3j,
credentials,
512512);
chainId);
RawTransaction rawTransaction = RawTransaction.createTransaction(
nonce,
gasPrice,
......@@ -127,11 +127,11 @@ public class SignAndSubmit {
}
}
public static void signAfterSubmit(String rpcUrl, String fromPk, String toAddress, String amount) {
public static void signAfterSubmit(String rpcUrl, String fromPk, String toAddress, String amount,long chainId) {
try {
SignAndSubmit signAndSubmit = new SignAndSubmit(rpcUrl);
// sign transaction
byte[] signMessage = signAndSubmit.offlineSign(fromPk, toAddress, new BigInteger(amount));
byte[] signMessage = signAndSubmit.offlineSign(fromPk, toAddress, new BigInteger(amount),chainId);
if (Objects.isNull(signMessage)) {
return;
}
......@@ -145,10 +145,10 @@ public class SignAndSubmit {
}
}
public static boolean signAndSubmit(String rpcUrl, String fromPk, String toAddress, String amount) {
public static boolean signAndSubmit(String rpcUrl, String fromPk, String toAddress, String amount,long chainId) {
try {
SignAndSubmit signAndSubmit = new SignAndSubmit(rpcUrl);
return signAndSubmit.signAndSend(fromPk, toAddress, new BigInteger(amount));
return signAndSubmit.signAndSend(fromPk, toAddress, new BigInteger(amount),chainId);
} catch (Exception e) {
web3j.shutdown();
System.out.println("transaction failed,exception:" + e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment