-
Notifications
You must be signed in to change notification settings - Fork 31
Operations
Attention: The method shown below have been introduced with SteemJ version 0.4.0 and will not be available in older versions.
All activities that change data on the blockchain, e.g. voting, posting or transfering, require a complex process to be fulfilled. To write data on the blockchain so called Operations are needed which are grouped in Transactions, signed by your privateKey and then broadcasted to a Steem Node.
SteemJ version 0.4.0 implements the mechanism known from the Steem CLI Wallet to simplfy the usage of Operations. This article shows and describes the currently available methods and provides some usefull snippets. If the operations shown here do not fullfil your requirements you can still create and broadcast your own operations like it has been done in older versions of SteemJ. Additional information can also be find in the How to perform Operations article of this Wiki.
To use the simplified Operation calls you need to configure a default account in SteemJ.
SteemJConfig myConfig = SteemJConfig.getInstance();
myConfig.setDefaultAccount(new AccountName("yourAccountName"));And provide the private posting key of this account.
List<ImmutablePair<PrivateKeyType, String>> privateKeys = new ArrayList<>();
privateKeys.add(new ImmutablePair<>(PrivateKeyType.POSTING, "YOURPRIVATEPOSTINGKEY"));
[... Add more keys if needed ... ]
myConfig.getPrivateKeyStorage().addAccount(myConfig.getDefaultAccount(), privateKeys);Now you can use the methods described below.
TOC
- Vote For A Post Or A Comment
- Cancel Your Vote
- Follow Someone
- Unfollow Someone
- Create A Post
- Create A Comment
- Update A Post
- Update A Comment
- Delete A Post Or A Comment
Voting for a post or a comment requires three parameters in total:
- The
authorof the post or comment to vote for (e.g. "dez1337") - The
permlinkof the post or the comment (e.g. "steem-java-api-learned-to-speak-graphene-update-5") - And the
weightyou want to vote with (e.g. 50% of your voting power)
Now provide all three parameters to the vote method of SteemJ:
steemJ.vote(new AccountName("dez1337"), new Permlink("steem-java-api-learned-to-speak-graphene-update-5"), (short) 50);To cancel the vote you just made simply provide:
- The
authorof the post or comment to remove the vote from (e.g. "dez1337") - The
permlinkof the post or the comment (e.g. "steem-java-api-learned-to-speak-graphene-update-5")
Now provide all three parameters to the cancelVote method of SteemJ:
steemJ.cancelVote(new AccountName("dez1337"), new Permlink("steem-java-api-learned-to-speak-graphene-update-5"));To follow someone you only need to know the account name of the person to follow.
steemJ.follow(new AccountName("cyriana"));To unfollow the person again, simply call the unfollow method:
steemJ.unfollow(new AccountName("cyriana"));To create a post some more parameters are required:
- The
titleof the post (e.g. "My new Post") - The
contentof the post - The
tagsyou want to use (e.g. "steemit", "steem", "steemj") - You have to use between one and five tags.
Now provide all three parameters to the createPost method:
steemJ.createPost("My new Post", "Test using SteemJ 0.4.0 by @dez1337 with a link to https://github.com/marvin-we/steem-java-api-wrapper and an image .", new String[] { "steemit", "steem", "steemj" });Attention SteemJ will internally generate a lot of other parameters based on the given values. One of this parameters is for example the permlink of your new post. As this permlink could be required for further actions, it is also possible to get the final Operation send to the Steem Node:
CommentOperation myNewPost = steemJ.createPost("My new Post"[...]
System.out.println("SteemJ has generated the following Permlink for my post: " + myNewPost.getPermlink().getLink());Writing a comment works like writing a post, but requires two additional parameters:
- The
parentAuthorwhich is the account that has written the post or comment you want to reply to (e.g. "steemj") - And the
parentPermlinkwhich is the permlink of the post or comment to reply to (e.g. "testofsteemj040") Beside that we still need: - The
contentof the post - And the
tagsyou want to use (e.g. "steemit", "steem", "steemj") - You have to use between one and five tags.
Now use the createComment method to reply to a post or another comment.
steemJ.createComment(new AccountName("steemj"), new Permlink("testofsteemj040"), "Example comment without a link but with a @user.", new String[] { "test" });Updating a post requires you to provide the original permlink of the post so the Steem Node knows that you want to update an existing post:
- The
permlinkOfThePostToUpdate(e.g. "testofsteemj040")
Attention It the permlink is not configured currently, SteemJ could accedently create a new post instead of updating an existing one.
Beside that you pretty much define the same parameters than you do for a normal post operation:
- The
titleof the post (e.g. "Test of SteemJ 0.4.0 update method") - The
contentof the post (e.g. "I do not like the old article") - The
tagsyou want to use (e.g. "steemit", "steem", "steemj") - You have to use between one and five tags. Attention The first tag is used by Steem to identify the original post and therefore is not allowed to change.
steemJ.updatePost(new Permlink("testofsteemj040"), "Test of SteemJ 0.4.0 update method", "I do not like the old article", new String[] { "test", "dontvote" });Deleting a post or a comment is quite easy. Simply provide the permlink of the post or comment you want to delete and provide this parameter to the SteemJ delete method:
steemJ.deletePostOrComment(new Permlink("testofsteemj040"));This project is developed by dez1337