New to Nutbox?

Programming Diary #2: Mixing it up with SteemJ, Broadcasting Steem transactions in Java, and Posting to Steem from a GUI

19 comments

remlaps
74
3 years agoSteemit6 min read

After several days of spinning my wheels, I finally have some progress to report. Here's another update on my activity learning to use Java for interaction with Steem's Steem Links Community.


Introduction

image.png

Pixabay license: source

After the holiday, I returned to work, so my programming time has been substantially limited this week, but I still found some time during the last two week-ends. Most of my programming time was spent trying to figure out how to submit a Steem transaction through SteemJ. It turns out that the version of SteemJ that I had downloaded was not functional for that purpose. Although I had been able to read information from the blockchain, I was not able to broadcast a transaction. After giving up on that version, I tried out a couple others until I finally found one that enabled me to broadcast a transaction. Once that was accomplished, I was quickly able to plug it into the previously created form and use the form to drive the transactions.

Basically, I met three goals during the past two week-ends:

  • Prove that I can broadcast something to the Steem blockchain using Java and SteemJ
  • Prove that I can use a button from a Java/Swing form to broadcast something to the Steem blockchain
  • Prove that I can collect data from a Java/Swing form and use it to populate a Steem post.

I also did some playing around with form design.

Here are some details about my progress during the last two week-ends.

Finding a suitable version of SteemJ

Basically, all of the programming time from my previous post until yesterday was spent troubleshooting the reason why I couldn't broadcast a transaction. I probably spent about 2 days working with the original version of SteemJ that I had downloaded, then yesterday, I finally gave up on that version and hunted around for other options. In the end, the configuration I found that works was to put these settings into my pom.xml file.

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependencies>
<dependency>
    <groupId>com.github.muksihs.steem-java-api-wrapper</groupId>
    <artifactId>steemj-core</artifactId>
    <version>0.4.6-20180926-01</version>
    </dependency>
</dependencies>

Once I found that configuration, it became very simple to meet the first goal, broadcasting a transaction to the Steem blockchain.

Transacting on the Steem blockchain (with or without a GUI)

For testing, I am using the Steem account, @social. I have no idea who created this account, but its posting key was intentionally released to the public, which turns out to be convenient for a purpose like this, where I don't want to risk accidental disclosure of my own key during testing. I modeled my code after this example, which describes how to set up a key and post a comment. After some simple substitutions, I came up with this code to set the keys:

SteemJConfig myConfig = SteemJConfig.getInstance();
myConfig.setDefaultAccount(new AccountName("social"));

List<ImmutablePair<PrivateKeyType, String>> privateKeys = new ArrayList<>();
privateKeys.add(new ImmutablePair<>(PrivateKeyType.POSTING, 
    "POSTING_KEY_FOR_@social"));
myConfig.getPrivateKeyStorage().addAccount(myConfig.getDefaultAccount(), privateKeys);

And this code to submit a post:

SteemJ steemJ = new SteemJ();
steemJ.createPost(String Title, String Body, String[] { "list", "of", "tags"} );

Conveniently, Netbeans knows how to set up the necessary imports, but here they are, just for reference:

/**

  • SteemJ imports

*/

import eu.bittrade.libs.steemj.SteemJ;
import eu.bittrade.libs.steemj.base.models.AccountName;
import eu.bittrade.libs.steemj.base.models.Permlink;
import eu.bittrade.libs.steemj.configuration.SteemJConfig;
import eu.bittrade.libs.steemj.enums.PrivateKeyType;
import java.util.ArrayList;

Using Java/Swing forms with SteemJ to create and submit Steem transactions

After I had this sort of thing working in a throwaway program, I went ahead and moved into the SteemLinksCreator form that I had cobbled together before my previous Programming Diary. The form now looks like this:

image.png

And the actions necessary to create a post are:

  1. Paste a URL into the form.
  2. Click on the AutoPopulate button
  3. Fill out additional fields that don't populate automatically
  4. Click on the "Generate HTML/Markdown" button
  5. Inspect the output text area to make sure it looks correct
  6. Press the "Post to Steem" button.

And here is a sample post, Confirmed: Your iPhone is lying to you | ZDNet - ZDNet.

Conclusion

After a frustrating few days fighting with the older version of SteemJ, I'm finally pleased with the progress I made yesterday and today. There's a long way to go to have something that I'd want to put in front of anyone other than myself, but I think that all of the fundamental building blocks are now in place. In no particular order, here are just some of the things I plan to add, when time allows:

  • Figure out how to download the functional version of SteemJ and update its dependencies to current versions.
  • Manual entry of account name and Posting key (in a password field).
  • Add fields to specify tags.
  • Figure out how to apply beneficiary settings to a post through SteemJ.
  • Provide a checkbox and entry field to set @penny4thoughts as a beneficiary and specify the percentage.
  • Figure out how to scrape the publication date from a web site using jSoup.
  • Put min/max lengths on blockquotes and author commentary.
  • Require a publication date.
  • Protect against accidentally double-posting from the same form data.
  • Protect against accidentally clearing the form before posting. (thanks for the suggestion, @cmp2020!)
  • Add the ability to "preview" a post before submitting to the blockchain.
  • Lots of error handling, all over the place.

Additionally, I have a puzzle to solve with Netbeans. For some reason, the Palette chooser for GUI design disappeared from Netbeans on my laptop. I have no idea how I managed to get rid of it, but I would like to figure out how to get that back. Adding graphical objects like buttons and text fields is more cumbersome without it.

I am not sure if anyone still has access to the @steemj wallet, but I'm setting it as 5% beneficiary, anyway. Hopefully the developer can still benefit from that. If not, it removes the rewards from circulation.


Thank you for your time and attention.

As a general rule, I up-vote comments that demonstrate "proof of reading".




Steve Palmer is an IT professional with three decades of professional experience in data communications and information systems. He holds a bachelor's degree in mathematics, a master's degree in computer science, and a master's degree in information systems and technology management. He has been awarded 3 US patents.

Comments

Sort byBest