Skip to content

SteemJConfig

dez1337 edited this page Dec 3, 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.

Node Endpoint

By default, SteemJ version 0.4.2 and greater is configured to use the official HTTP endpoint provided by Steem ('https://api.steemit.com'). This configuration is adequate for most usecases as the most common plugins are enabled. However, if you want to add additional nodes or connect to a WebSocket endpoint as older versions of SteemJ have done it, the following example shows how to add those endpoints to the connection pool.

try {
        ArrayList<Pair<URI, Boolean>> endpoints = new ArrayList<>();

        ImmutablePair<URI, Boolean> webSocketEndpointOne = new ImmutablePair<>(new URI("wss://steemd.steemit.com"), true);
        ImmutablePair<URI, Boolean> webSocketEndpointTwo = new ImmutablePair<>(new URI("wss://seed.bitcoiner.me"), true);
        ImmutablePair<URI, Boolean> webSocketEndpointThree = new ImmutablePair<>(new URI("wss://steemd.minnowsupportproject.org"), true);

        endpoints.add(webSocketEndpointOne );
        endpoints.add(webSocketEndpointTwo );
        endpoints.add(webSocketEndpointThree );

        myConfig.setEndpointURIs(endpoints);
} catch (URISyntaxException e) {
        throw new RuntimeException("The given URI is not valid.", e);
}

If you want to override the whole pool you can do it like this:

try {
        // Reset the currently configured endpoints.
        myConfig.setEndpointURIs(new ArrayList<Pair<URI, Boolean>>());
        // Change the default settings if needed.
        myConfig.addEndpointURI(new URI("wss://seed.bitcoiner.me"), true);
} catch (URISyntaxException e) {
        throw new RuntimeException("The given URI is not valid.", e);
}

Back to TOC

Response 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.setResponseTimeout(100000L);

Or disale it completly.

myConfig.setTimeout(0L);

Back to TOC

Socket Timeout

By default SteemJ will close an unused connection after 1 minute of inactivity and reconnect if the connection is used again. Some users reported that one minute is not enough so the socketTimeout parameter has been introduced. This parameter allows you to define when an idle connection should be closed.

myConfig.setSocketTimeout(100000L);

The timeout can also be disabled by setting it to 0.

myConfig.setSocketTimeout(0L);

Please be informed that this only effects the SteemJ timeout. If the node itself has an idle timeout configured the connection will still be closed. Therefore, SteemJ comes with a reconnect mechanism that will also protected the connection in case of a node closing the connection.

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.setApiUsername(new AccountName("userallowedtoaccessapi"));
myConfig.setApiPassword("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

Default Account

To simplify Operations SteemJ allows to define a default account that will always be used for Simplified Operations.

myConfig.setDefaultAccount(new AccountName("steemj");

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

Address Prefix

SteemJ is predefined to work with the Steem blockchain. However, if you work against a different blockchain or the Steem Test Net, you need to provide a different address prefix to handle keys.

myConfig.setAddressPrefix(SteemitAddressPrefix.STM);

Back to TOC

Chain ID

SteemJ is predefined to work with the Steem blockchain. However, if you work against a different blockchain or the Steem Test Net, you need to provide a different chain id.

myConfig.setChainId("00000000000000000000000000000000");

Back to TOC

Validation Level

Since SteemJ Version 0.4.0 SteemJ will validate all operations before sending them to a Steem Node to avoid sending transactions that will be rejected anyway. However, this checks only work against the official Steem Chain - In case you work against a different chain you may want to adjust the validation level or disable the whole validation.

myConfig.setValidationLevel(ValidationType.SKIP_VALIDATION);

Back to TOC

SteemJ Weight

This option can be used to support SteemJ. If set to a value greater than 0 a BeneficiaryRoute will be added. The weight can be changed as shown below.

myConfig.setSteemJWeight((short)1000);

Back to TOC

Expected Symbol Types

SteemJ 0.4.0 added a build in validation to a lot of methods and objects, but was hardcoded to use the normal Steem Token Types (SBD, STEEM, VESTS). As you may want to work against other chains or a TestNet where other Symbol Types are used, SteemJ now allows to define the expected token types.

myConfig.setDollarSymbol(AssetSymbolType.SBD);
myConfig.setTokenSymbol(AssetSymbolType.TEST);
myConfig.setVestsSymbol(AssetSymbolType.VESTS);

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.username 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

Default Account

To set the default account using a System property, set the following parameter.

Parameter Description Example
steemj.default.account The default account java -jar yourApp.jar -Dsteemj.default.account="dez1337"

Back to TOC

Private Keys

Beside your credentials you can also provide the keys of the default account through system properties.

Parameter Description Example
steemj.default.account.posting.key The private posting key of the default account java -jar yourApp.jar -Dsteemj.default.account.posting.key="5JpbHHrEkoLsxNcddo5YaTgtmgDegTcjk8i7BDPiTbMefrPnjWK"
steemj.default.account.active.key The private active key of the default account java -jar yourApp.jar -Dsteemj.default.account.active.key="5J6a9B9H1rBC9XsxHUrv9Eu98cG4MaZPuaMk6LBfMSDGyk5SoiP"
steemj.default.account.owner.key The private ownerkey of the default account java -jar yourApp.jar -Dsteemj.default.account.owner.key ="5JhxZZ6oGwFm2egPWyy21DWvroSoUur33sEHBamobDdSmhPN9U4"
steemj.default.account.memo.key The private memo key of the default account java -jar yourApp.jar -Dsteemj.default.account.memo.key="5Hw3qRsC3f9yLtVazZpA8LyCUozBJq5aQv9tNNnz8fcg8BqoAWw"

Back to TOC

Clone this wiki locally