-
Notifications
You must be signed in to change notification settings - Fork 28
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
- Reblog A Post
- Create A Post
- Create A Comment
- Update A Post
- Update A Comment
- Delete A Post Or A Comment
- Transfer Your Tokens
- Delegate SteemPower To Another Account
- Claim Your Rewards
Voting for a post or a comment requires three parameters in total:
- The
author
of the post or comment to vote for (e.g. "dez1337") - The
permlink
of the post or the comment (e.g. "steem-java-api-learned-to-speak-graphene-update-5") - And the
weight
you 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
author
of the post or comment to remove the vote from (e.g. "dez1337") - The
permlink
of 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"));
Use this method to reblog/resteem a post of another author to share it with your community.
The 'reblog' method requires two parameters in total:
- The
authorOfThePostToReblog
of the post to reblog/resteem (e.g. "dez1337") - The
permlinkOfThePostToReblog
of the post to reblog/resteem (e.g. "steem-java-api-learned-to-speak-graphene-update-5")
Please be aware that there is no way to undo a reblog operation. If you are sure about resteeming a post a full example would look like this:
steemJ.reblog(new AccountName("dez1337"), new Permlink("steemj-v0-4-0-has-been-released-integrate-steem-into-your-java-project"));
To create a post some more parameters are required:
- The
title
of the post (e.g. "My new Post") - The
content
of the post - The
tags
you 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 ![SteemJV2Logo](https://imgur.com/bIhZlYT.png).", 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
parentAuthor
which is the account that has written the post or comment you want to reply to (e.g. "steemj") - And the
parentPermlink
which is the permlink of the post or comment to reply to (e.g. "testofsteemj040") Beside that we still need: - The
content
of the post - And the
tags
you 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 If 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
title
of the post (e.g. "Test of SteemJ 0.4.0 update method") - The
content
of the post (e.g. "I do not like the old article") - The
tags
you 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" });
To update a comment the following parameters are required:
- The
authorOfTheParentPostOrComment
(e.g. "steemj") - The
permlinkOfTheParentPostOrComment
(e.g. "testofsteemj040") - The
permlinkOfTheCommentToUpdate
(e.g. "re-steemj-testofsteemj040-1507375770184t6e18f3f6-a356-4a21-8591-b0da5a6b78fduid") - The new
content
(e.g. "Updated the comment") - The
tags
you 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.updateComment(new AccountName("steemj"), new Permlink("testofsteemj040"),
new Permlink("re-steemj-testofsteemj040-1507375770184t6e18f3f6-a356-4a21-8591-b0da5a6b78fduid"),
"Updated the comment", 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"));
The method shown below allows you to transfer the Token of your choice (STEEM, SBD, VESTS/SteemPower) to another account by providing the following parameters:
- The target account (e.g.
dez1337
) - The amount and Token type to transfer (e.g.
1.0 STEEM
) - A message (e.g.
Hello @dez1337 - I've send you one STEEM.
)
steemJ.transfer(new AccountName("dez1337"), new Asset(1.0, AssetSymbolType.STEEM), "Hello @dez1337 - I've send you one STEEM.");
Use this method to delegate your SteemPower to another account.
When SteemPower is delegated it is basically added to the SteemPower of the target account while the target account is not able to transfer or withdraw this SteemPower. The main usage of this functionallity is to support other users or innitiatives.
Delegating SteemPower with SteemJ can be done by providing the following twi parameters to the delegateVestingShares
method:
- The target account
- The amount to send (Make sure that VESTS is used as the Symbol)
steemJ.delegateVestingShares(new AccountName("dez1337"), new Asset(10L, AssetSymbolType.VESTS));
The sample above would delegate 0.00010 VESTS
to dez1337
.
This method allows you to claim the rewards of an account.
steemJ.claimRewards();
The method has the same functionallity as the "Redeem Rewards" button in your Steemit.com Wallet.
This project is developed by dez1337