Developers wishing to use IOTA Blockchain end up learning a lot in depth in IOTA, which is a good thing. At the same time, it is cubersome to build micro services based on IOTA and especially if one wishes to use the
Multisignature feature that IOTA provides. The IOTA API 1.0.0-beta9, offers primitive support for Multisignature transactions. Compared to IOTA API's normal transactions, Multisignature transaction features has a lot of gap when it comes to developer friendliness. This library aims to bridge the gap and provide an easy to use API on top of IOTA API and comes with Spring integration.
A microservice can simply add this library to its dependency and can start using it.
Include the following maven dependency in your microservice. The artifacts are available in Maven central.
<dependency>
<groupId>io.github.balsmn</groupId>
<artifactId>iota-utils-ext</artifactId>
<version>${latest.version}</version>
</dependency>
Include the following maven dependency and snapshot repository to your repository list in your microservice
<dependency>
<groupId>io.github.balsmn</groupId>
<artifactId>iota-utils-ext</artifactId>
<version>${latest.snapshot.version}</version>
</dependency>
<repositories>
<repository>
<id>ossrh-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
Add the following to your spring application configurations
iota:
config:
host: nodes.devnet.iota.org
seedSecurityLevel: 1
testMode: true
Then add the following component scan to your spring application
@ComponentScan("io.github.balsmn")
The following example shows, some of the basic use of the library
// inject accountManager using spring dependency injection
private AccountManager accountManager;
// inject config using spring dependency injection
private final BlockchainClientConfig config;
.....
AccountResponse normalAccountResponse = accountManager.createNewAccount();
AccountResponse multisigaccountResponse = accountManager.createNewMultisigAccount();
log.info("Normal account response : {}", accountManager.getAccountBalance(normalAccountResponse.getAccountAddress());
// generate a new remainder address where the balance ammount after
// transfer will be sent to.
String remainderAddress = IotaAPIHelper.createNewMultisigAddress(multisigaccountResponse.getAccountSeeds().get(0), multisigaccountResponse.getAccountSeeds().get(1), config.getSeedSecurityLevel());
String seed1 = multisigaccountResponse.getAccountSeeds().get(0);
String seed2 = multisigaccountResponse.getAccountSeeds().get(1);
List<Transaction> transactions = accountManager.sendMultisigTransaction(fromAccountAddress, remainderAddress, targetAccountAddress, seed1, seed2,2, 100, "my 2817 bytes long custom message", "my tag");
log.info("Remainder balancer : {}", accountManager.getAccountBalance(remainderAddress);
In the above code, 2 (during transfer) indicates securityLevel, the combination of both the seed's securityLevel. Based on iota.config.seedSecurityLevel configuration this can be calcualted.