-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathSendTransaction.java
More file actions
51 lines (38 loc) · 1.49 KB
/
SendTransaction.java
File metadata and controls
51 lines (38 loc) · 1.49 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
/// Sending Transactions
// In order to send, you need a Signer. The SimpleWallet class is a basic implementation which can be used.
package in3;
import in3.*;
import in3.eth1.*;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
public class SendTransaction {
//
public static void main(String[] args) throws IOException {
// create incubed
IN3 in3 = IN3.forChain(Chain.MAINNET); // set it to mainnet (which is also dthe default)
// create a wallet managing the private keys
SimpleWallet wallet = new SimpleWallet();
// add accounts by adding the private keys
String keyFile = "myKey.json";
String myPassphrase = "<secrect>";
// read the keyfile and decoded the private key
String account = wallet.addKeyStore(
Files.readString(Paths.get(keyFile)),
myPassphrase);
// use the wallet as signer
in3.setSigner(wallet);
String receipient = "0x1234567890123456789012345678901234567890";
BigInteger value = BigInteger.valueOf(100000);
// create a Transaction
TransactionRequest tx = new TransactionRequest();
tx.setFrom(account);
tx.setTo("0x1234567890123456789012345678901234567890");
tx.setFunction("transfer(address,uint256)");
tx.setParams(new Object[] {receipient, value});
String txHash = in3.getEth1API().sendTransaction(tx);
System.out.println("Transaction sent with hash = " + txHash);
}
}