SteemJ V0.4.0 Feature Preview – Simplified Transactions

Vote with one single command instead of programming 23 lines!


SteemJV2Logo

SteemJ V0.4.0 Feature Preview – Simplified Transactions

Hello Steemians!

I am really happy to say that this is the last planned feature for SteemJ 0.4.0 and that the new version will hopefully be released at Sunday after some final tests.

This feature preview is about a great improvement that you may already know from steem-python. I would call it Simplified Transactions.

The Problem

A lot of issues reported at GitHub are about the usage of Operations:

  • How can I follow someone?
  • How can I vote for a post?
  • How can I vote for a comment?
  • How can I update a comment?
  • How can I cancel my vote?
  • …..

And to be honest, understanding Operations, Transactions, the signing of Transactions and broadcasting them needs some general knowledge of how the process actually works. So even when I spend some time explaining and researching the answers for those questions I still have the feeling that the questioner does not always understand what he has to do in detail and stops using SteemJ.

The Solution

To solve this problem the idea is to simply the usage of Operations as much as possible as steem-python is doing it too. SteemJ 0.4.0 will be shipped with methods that cover the most asked use cases:

  • upVote
  • downVote
  • cancelVote
  • follow
  • unfollow
  • createPost
  • createComment
  • updatePost
  • updateComment
  • deletePost
  • deleteComment

Examples

I guess the list above does not sound as impressive as the feature actually is, so here are two examples showing the difference.

UpVote

With older SteemJ versions performing an up vote had to be done like this:

// Perform a transaction
AccountName voter = new AccountName("dez1337");
AccountName author = new AccountName("dez1337");
Permlink permlinkOfAPost = new Permlink("steem-java-api-learned-to-speak-graphene-update-5");
Short votingWeight = 10000;
VoteOperation voteOperation = new VoteOperation(voter, author, permlinkOfAPost, votingWeight);

ArrayList<Operation> operations = new ArrayList<>();
operations.add(voteOperation);

// Get the current RefBlockNum and RefBlockPrefix from the global
// properties.
GlobalProperties globalProperties = steemJ.getDynamicGlobalProperties();

SignedTransaction signedTransaction = new SignedTransaction(globalProperties.getHeadBlockId(), operations,
    null);

try {
    signedTransaction.sign();
} catch (SteemInvalidTransactionException e) {
    LOGGER.error("A propblem occured while signing your Transaction.", e);
}
steemJ.broadcastTransaction(signedTransaction);

With SteemJ version 0.4.0 you will be able to do a vote using the ‘vote()’ method.

steemJ.vote(new AccountName("dez1337"), new Permlink("steem-java-api-learned-to-speak-graphene-update-5"), (short) 100);

Follow

With older SteemJ versions following someone looked like this:

ArrayList<AccountName> requiredPostingAuths = new ArrayList<>();
requiredPostingAuths.add(new AccountName("dez1337"));

// Steem does not allow to combine operations that require a posting key
// with operations that require a higher key, so set the active
// authorities to null.
ArrayList<AccountName> requiredActiveAuths = null;

String id = "follow";
String json = "[\"follow\",{\"follower\":\"dez1337\",\"following\":\"steemj\",\"what\":[\"blog\"]}]";

CustomJsonOperation customJsonOperation = new CustomJsonOperation(requiredActiveAuths, requiredPostingAuths, id,
                json);

ArrayList<Operation> operations = new ArrayList<>();
operations.add(customJsonOperation);

// Get the current RefBlockNum and RefBlockPrefix from the global
// properties.
GlobalProperties globalProperties = steemJ.getDynamicGlobalProperties();

SignedTransaction signedTransaction = new SignedTransaction(globalProperties.getHeadBlockId(), operations,
    null);

try {
    signedTransaction.sign();
} catch (SteemInvalidTransactionException e) {
    LOGGER.error("A propblem occured while signing your Transaction.", e);
}
steemJ.broadcastTransaction(signedTransaction);

With SteemJ version 0.4.0 you will be able to follow someone using the ‘follow()’ method.

steemJ.follow(new AccountName("cyriana"));

I hope you like this feature as much as I do! :)

General information

What is SteemJ?

SteemJ is a project that allows you to communicate with a Steem node using Java. So far, the project supports most of the API calls and is also able to broadcast most of the common operation types. Further information can be found on GitHub.

https://github.com/marvin-we/steem-java-api-wrapper

How to add it to your project?

SteemJ binaries are pushed into the maven central repository and can be integrated with a bunch of build management tools like Maven. The Wiki provides a lot of examples for the most common build tools. If you do not use a build management tool you can download the binaries as described here.

Contribute

The project became quite big and there is still a lot to do. If you want to support the project simply clone the git repository and submit a pull request. I would really appreciate it =).

git clone https://github.com/marvin-we/steem-java-api-wrapper.git

Get in touch!

Most of my projects are pretty time consuming and I always try to provide some useful stuff to the community. What keeps me going for that is your feedback and your support. For that reason I would love to get some Feedback from you <3. Just contact me here on Steemit or ping me on GitHub.


If you want to stay up to date or just like the stuff I am doing it would be great if you could press the button below =).

Follow meFollow @dez1337
follow mefollow dez1337


Thanks for reading and best regards,
@dez1337

H2
H3
H4
3 columns
2 columns
1 column
4 Comments