Skip to content

Commit 882e874

Browse files
committed
readme, private key from mnemonic in core sdk
1 parent 5100b1d commit 882e874

File tree

3 files changed

+139
-13
lines changed

3 files changed

+139
-13
lines changed

README.md

Lines changed: 133 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Minter Android Blockchain API SDK
22
=================================
33
[![Download](https://api.bintray.com/packages/minterteam/android/minter-android-blockchain-testnet/images/download.svg) ](https://bintray.com/minterteam/android/minter-android-blockchain-testnet/_latestVersion)
4-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.txt)
55

66

77
Minter blockchain sdk library
@@ -36,18 +36,141 @@ dependencies {
3636
}
3737
```
3838

39-
## Basic Usage
40-
### Initialize it
41-
```java
39+
## Usage / Examples
40+
### 1. Initialize SDK
4241

42+
Use our nodes
43+
```java
4344
MinterBlockChainApi.initialize();
4445
```
4546

46-
### Usage
47-
Look at [tests](src/tests/java/network/minter/blockchain) to see how to create and sign transactions
47+
Or you can pass you own
48+
```java
49+
MinterBlockChainApi.initialize("https://your-node.local");
50+
```
51+
52+
### 2. Creating and signing transactions
53+
54+
Transactions API uses **Builder** pattern, so it so easy to handle it.
55+
56+
All transactions requires a valid **nonce** value. Nonce - is a number of transaction. To get valid transaction number, you should get current number via `BlockChainAccountRepository#getTransactionCount` and increment it:
57+
58+
```java
59+
// init object with your Minter address
60+
MinterAddress myAddress = new MinterAddress("Mxccc3fc91a3d47dc1ee26d62611a09831f0214d62");
61+
62+
// get account repository from SDK singleton object
63+
BlockChainAccountRepository repo = MinterBlockChainApi.getInstance().account();
64+
65+
// send request
66+
repo.getTransactionCount(myAddress).enqueue(new Callback<BCResult<CountableData>>() {
67+
@Override
68+
public void onResponse(Call<BCResult<CountableData>> call, Response<BCResult<CountableData>> response) {
69+
BigInteger txCount = response.body().result.count;
70+
71+
// use this incremented value as nonce to your transaction
72+
BigInteger nonce = txCount.add(new BigInteger("1"));
73+
}
74+
75+
@Override
76+
public void onFailure(Call<BCResult<CountableData>> call, Throwable t) {
77+
}
78+
})
79+
```
80+
81+
#### 2.1 Create "Send" transaction
82+
Calculate nonce (see above)
83+
```java
84+
// Calculated nonce
85+
BigInteger nonce = ...
86+
```
87+
88+
Create your private key to sign tx with it:
89+
```java
90+
PrivateKey privateKey = new PrivateKey("4c9a495b52aeaa839e53c3eb2f2d6650d892277bde58a24bb6a396f2bb31aa37");
91+
```
92+
93+
or if you know only mnemonic phrase, you can do this:
94+
```java
95+
final PrivateKey privateKey = PrivateKey.fromMnemonic("your phrase must contains twenty words et cetera ...");
96+
```
97+
98+
Create transaction builder and build transaction:
99+
```java
100+
Transaction tx = new Transaction.Builder(new BigInteger("1"))
101+
// optional: available for all transactions, but not useful for some transactions
102+
.setGasCoin("MNT")
103+
// here you should select what transaction you are trying to create, builder will select exact type
104+
.sendCoin()
105+
// required: coin to send
106+
.setCoin(coin)
107+
// required: value to send
108+
.setValue(10D)
109+
// required: recipient address
110+
.setTo(toAddress)
111+
// finally, build object
112+
.build();
113+
```
114+
115+
Sign transaction using your private key
116+
```java
117+
TransactionSign sign = tx.sign(privateKey);
118+
119+
// get transaction hash - this hash you'll send to blockchain
120+
String signedTransaction = sign.getTxSign();
121+
```
122+
123+
124+
So, it's easy, isn't? :)
125+
126+
For more transaction types see `OperationType` and class `Transaction.Builder`
127+
128+
Now we'll send transaction to blockchain.
129+
130+
#### 2.2 Send "send" transaction to the Minter blockchain
131+
132+
To send transaction to blockchain, we need to get `BlockChainAccountRepository` from `MinterBlockChainApi`
133+
134+
```java
135+
BlockChainAccountRepository accountRepo = MinterBlockChainApi.getInstance().account();
136+
```
137+
138+
To send transaction, you just need to call http request
139+
```java
140+
TransactionSign sign = ...
141+
accountRepo.sendTransaction(sign).enqueue(new Callback<BCResult<TransactionSendResult>>() {
142+
@Override
143+
public void onResponse(Call<BCResult<TransactionSendResult>> call, Response<BCResult<TransactionSendResult>> response) {
144+
// handle send result
145+
}
146+
147+
@Override
148+
public void onFailure(Call<BCResult<TransactionSendResult>> call, Throwable t) {
149+
// handle send error
150+
}
151+
})
152+
```
153+
154+
That's all!
155+
156+
157+
## Documentation
158+
159+
Javadoc available in code and in *.jar file at the bintray
160+
161+
## Build
162+
TODO
163+
164+
## Tests
165+
TODO
166+
167+
## Changelog
168+
169+
See [Release notes](RELEASE.md)
170+
171+
172+
## License
48173

49-
## Docs
50-
TODO (tests and javadocs available for now)
174+
This software is released under the [MIT](LICENSE.txt) License.
51175

52-
# Build
53-
TODO
176+
© 2018 MinterTeam <[email protected]>, All rights reserved.

RELEASE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Release notes
22

3+
## 0.1.2
4+
- updated core sdk to creating private key from mnemonic phrase directly
5+
36
## 0.1.1
47
- Added signed transaction commission calculation endpoint.
58
- Target api 28

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ apply plugin: 'com.jfrog.bintray'
5858

5959

6060
group = 'network.minter.android'
61-
version = '0.1.1'
61+
version = '0.1.2'
6262

6363
ext {
6464
minterMinSdk = 16
6565
minterMaxSdk = 28
6666
minterBuildTools = "28.0.2"
6767
minterLibSupport = "27.1.1"
68-
minterCoreVers = version
68+
minterCoreVers = "0.1.3"
6969
pomDescription = "Minter Android Blockchain API SDK"
7070
}
7171

@@ -84,7 +84,7 @@ android {
8484
minSdkVersion minterMinSdk
8585
targetSdkVersion minterMaxSdk
8686

87-
versionCode 1
87+
versionCode 2
8888
versionName version
8989

9090
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

0 commit comments

Comments
 (0)