-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathSolSample.java
More file actions
54 lines (48 loc) · 1.59 KB
/
SolSample.java
File metadata and controls
54 lines (48 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.ethjava.sol;
import com.ethjava.utils.Environment;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.http.HttpService;
import org.web3j.utils.Convert;
import java.math.BigInteger;
public class SolSample {
public static void main(String[] args) {
deploy();
use();
}
private static void deploy() {
Web3j web3j = Web3j.build(new HttpService(Environment.RPC_URL));
Credentials credentials = null;//可以根据私钥生成
RemoteCall<TokenERC20> deploy = TokenERC20.deploy(web3j, credentials,
Convert.toWei("10", Convert.Unit.GWEI).toBigInteger(),
BigInteger.valueOf(3000000),
BigInteger.valueOf(5201314),
"my token", "mt");
try {
TokenERC20 tokenERC20 = deploy.send();
tokenERC20.isValid();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void use() {
Web3j web3j = Web3j.build(new HttpService(Environment.RPC_URL));
String contractAddress = null;
Credentials credentials = null;//可以根据私钥生成
TokenERC20 contract = TokenERC20.load(contractAddress, web3j, credentials,
Convert.toWei("10", Convert.Unit.GWEI).toBigInteger(),
BigInteger.valueOf(100000));
String myAddress = null;
String toAddress = null;
BigInteger amount = BigInteger.ONE;
try {
BigInteger balance = contract.balanceOf(myAddress).send();
TransactionReceipt receipt = contract.transfer(toAddress, amount).send();
//etc..
} catch (Exception e) {
e.printStackTrace();
}
}
}