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

remlaps -

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


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:

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:

/**

*/

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:

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:

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.