Commit 28012cd9 authored by duanjinfei's avatar duanjinfei

add params chainId

parent bc470641
...@@ -66,7 +66,7 @@ public class SignAndSubmit { ...@@ -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 { try {
BigInteger nonce = getAddressNonce(fromPk); BigInteger nonce = getAddressNonce(fromPk);
System.out.println("Nonce:" + nonce); System.out.println("Nonce:" + nonce);
...@@ -84,14 +84,14 @@ public class SignAndSubmit { ...@@ -84,14 +84,14 @@ public class SignAndSubmit {
value, value,
""); "");
System.out.println("toAddress:" + toAddress); System.out.println("toAddress:" + toAddress);
return TransactionEncoder.signMessage(rawTransaction, 512512, credentials); return TransactionEncoder.signMessage(rawTransaction, chainId, credentials);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
} }
public boolean signAndSend(String fromPk, String toAddress, BigInteger value) { public boolean signAndSend(String fromPk, String toAddress, BigInteger value,long chainId) {
try { try {
BigInteger nonce = getAddressNonce(fromPk); BigInteger nonce = getAddressNonce(fromPk);
System.out.println("Nonce:" + nonce); System.out.println("Nonce:" + nonce);
...@@ -100,7 +100,7 @@ public class SignAndSubmit { ...@@ -100,7 +100,7 @@ public class SignAndSubmit {
Credentials credentials = Credentials.create(fromPk); Credentials credentials = Credentials.create(fromPk);
RawTransactionManager transactionManager = new RawTransactionManager(web3j, RawTransactionManager transactionManager = new RawTransactionManager(web3j,
credentials, credentials,
512512); chainId);
RawTransaction rawTransaction = RawTransaction.createTransaction( RawTransaction rawTransaction = RawTransaction.createTransaction(
nonce, nonce,
gasPrice, gasPrice,
...@@ -127,11 +127,11 @@ public class SignAndSubmit { ...@@ -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 { try {
SignAndSubmit signAndSubmit = new SignAndSubmit(rpcUrl); SignAndSubmit signAndSubmit = new SignAndSubmit(rpcUrl);
// sign transaction // 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)) { if (Objects.isNull(signMessage)) {
return; return;
} }
...@@ -145,10 +145,10 @@ public class SignAndSubmit { ...@@ -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 { try {
SignAndSubmit signAndSubmit = new SignAndSubmit(rpcUrl); 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) { } catch (Exception e) {
web3j.shutdown(); web3j.shutdown();
System.out.println("transaction failed,exception:" + e); 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