Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
web3jdemo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanjinfei
web3jdemo
Commits
28012cd9
Commit
28012cd9
authored
Aug 24, 2022
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add params chainId
parent
bc470641
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
SignAndSubmit.java
src/main/java/com/cmp/signDemo/SignAndSubmit.java
+8
-8
No files found.
src/main/java/com/cmp/signDemo/SignAndSubmit.java
View file @
28012cd9
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment