Skip to content

SteemJConfig

dez1337 edited this page Aug 6, 2017 · 22 revisions

SteemJ comes with a common default configuration if you instantiate it which may not always fit your needs. This page describes which parameters can be changed and how the SteemJConfig works.

TOC

SteemJ is shipped with a default configuration that has been tested and that should allow you to execute all activities out of the box. For the case that this default configuration does not fit your needs you can find all required information in the following chapters to change it.

Before you continue to read you need to know one additional thing: SteemJConfig is Singleton, which means that there is only one existing instance per application. While this feature does not allow to define different configurations for different threads, it makes it unnecessary to pass the configuration object to every single method.

The following command shows how to get the currently used SteemJConfig-Instance.

[...]
SteemJConfig myConfig = SteemJConfig.getInstance();
[...]

Back to TOC

Configuration Examples

The following chapters explain and show the available configurations.

Steem Node Endpoint

By default, SteemJ connects to the official Websocket Endpoint of the Steemit Node (wss://node.steem.ws). This configuration is adequate for most usecases as the most common plugins are enabled. However, the following example shows how to connect to another Steem Node.

try {
        myConfig.setWebsocketEndpointURI(new URI("wss://this.piston.rocks"));
} catch (URISyntaxException e) {
        throw new RuntimeException("The given URI is not valid.", e);
}

Back to TOC

Timeout

To avoid that unanswered requests block your application forever, SteemJ has a build in Timeout mechanism. By default the Steem Node has to answer in 1 second, otherwise a TimeoutException will be thrown. If you have a slow internet connection or working with a huge dataset you can increase the timeout like shown in the example below.

myConfig.setTimeout(100000L);

Or disale it completly.

myConfig.setTimeout(0L);

Back to TOC

Date Time Pattern

SteemJ needs to parse dates provided by the Steem Node. By default, the pattern "yyyy-MM-dd'T'HH:mm:ss" and the timezone "GMT" are used by SteemJ. If you connect to a node returning dates in another format or with another timezone, you need to change the datetime pattern by providing the new pattern and the new timezone as shown below.

myConfig.setDateTime("yyyy-mm-dd'T'HH:mm:ss", "UTC");

Back to TOC

Maximum Expiration Date

The expiration date defines the datetime until a transaction needs to be processed by the blockchain. Beside that, the expiration date is not allowed to be too far in the future. The maximum allowed offset is defined by Steem and is currently set to 1 hour.

To increase the usability, SteemJ will use the current datetime and add the offset to it to calculate the latest possible expiration date. Example:

CurrentTime = 2017-07-08T13:20:15
MaximumOffset = 1 hour
MaximumExpirationDate = 2017-07-08T14:20:15

In case the Steem blockchain changes the maximum allowed offset, the transactions will be not be accepted because the expiration date is too far in the future. For this case SteemJ allows you to adjust the expiration date offset like shown in the following example.

myConfig.setMaximumExpirationDateOffset(40000L);

Back to TOC

Credentials

The owner of a Steem Node is able to protect API plugins by denying ananoumous access. If you are connected to a node whose APIs are protected you can add the required credentials using the sample below.

myConfig.setAccountName(new AccountName("userallowedtoaccessapi"));
myConfig.setPassword("mypassword".toCharArray());

Back to TOC

Disable SSL Verification

If SteemJ is connected to a Steem Node using WSS, but a non official SSL certificate is used, you can disable the SSL verification like shown below.

myConfig.setSslVerificationDisabled(true);

Back to TOC

Private Keys

Private keys are required when you want to "write" data to the block chain. In case of Steem this can in example be a Vote or a Transfer of SBD. In nearly all cases, the write operation needs to be signed with the private key of the initiator - So for a Vote operation the posting key of the account who wants to vote is required or for a transfer operation the active key of the account sending the money is required.

Since v0.3.2 SteemJ can handle the private keys of multiple accounts while it was only possible to store the private keys of a single account with earlier versions. The following example shows how to add private keys for different users to the PrivateKeyStorage of SteemJConfig.

List<ImmutablePair<PrivateKeyType, String>> privateKeys = new ArrayList<>();

privateKeys.add(new ImmutablePair<>(PrivateKeyType.POSTING, "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"));
privateKeys.add(new ImmutablePair<>(PrivateKeyType.ACTIVE, "6KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"));
privateKeys.add(new ImmutablePair<>(PrivateKeyType.OWNER, "7KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"));

myConfig.getPrivateKeyStorage().addAccount(new AccountName("dez1337"), privateKeys);

privateKeys = new ArrayList<>();

privateKeys.add(new ImmutablePair<>(PrivateKeyType.POSTING, "5ABwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"));
privateKeys.add(new ImmutablePair<>(PrivateKeyType.ACTIVE, "6ABwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"));
privateKeys.add(new ImmutablePair<>(PrivateKeyType.OWNER, "7ABwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"));

myConfig.getPrivateKeyStorage().addAccount(new AccountName("steemj"), privateKeys);

Back to TOC

Encoding Charset

Steam needs to serialize your inputs to send them to the Steem Node. Depending on which language and features you use in your in the text fields (like a post or a comment), a different Charset is needed.

Initially SteemJ was shipped with US_ASCII as the default setting. US_ASCII only needs one byte per Character and the idea was to minimize the traffic. When more and more people started to use SteemJ, it turns out that most of them want to use UTF-8 which is now the default since v0.3.2. Anyway, if you want to change the Charset you can do it like shown below.

myConfig.setEncodingCharset(StandardCharsets.US_ASCII);

Back to TOC

System Properties

SteemJ allows you to provide sensitive data as system properties.

Credentials

To provide credentials SteemJ should use to login into the node, you can use following parameters.

Parameter Description Example
steemj.api.accountName The username to login java -jar yourApp.jar -Dsteemj.api.accountName="dez1337"
steemj.api.password The password to login java -jar yourApp.jar -Dsteemj.api.password="secretPassword123"

Back to TOC

Private Keys

Beside your credentials you can also provide your keys through system properties.

Parameter Description Example
steemj.key.active The username to login java -jar yourApp.jar -Dsteemj.key.active="5JpbHHrEkoLsxNcddo5YaTgtmgDegTcjk8i7BDPiTbMefrPnjWK"
steemj.key.posting The password to login java -jar yourApp.jar -Dsteemj.key.posting="5J6a9B9H1rBC9XsxHUrv9Eu98cG4MaZPuaMk6LBfMSDGyk5SoiP"
steemj.key.owner The password to login java -jar yourApp.jar -Dsteemj.key.owner ="5JhxZZ6oGwFm2egPWyy21DWvroSoUur33sEHBamobDdSmhPN9U4"
steemj.key.memo The password to login java -jar yourApp.jar -Dsteemj.key.memo="5Hw3qRsC3f9yLtVazZpA8LyCUozBJq5aQv9tNNnz8fcg8BqoAWw"

Back to TOC

Clone this wiki locally