如何开始使用IOTA应用程序

时间:2019-01-26 18:56:07

标签: blockchain iot iota

我想开发IOTA应用程序,而不是消息传递应用程序或基于硬币的系统。我想要一个简单的示例,说明如何在IOTA中存储数据。例如,我想构建一个SCM甚至一个简单的登录/注册应用程序。谁能指导我?任何示例应用程序?我尝试运行https://github.com/domschiener/leaderboard-example,但遇到与https://github.com/domschiener/leaderboard-example/issues/6类似的错误,如何运行此错误。

1 个答案:

答案 0 :(得分:0)

将文本数据存储在纠结中并不难。以下是我基于缠结的应用程序的片段。我使用了IOTA的API Java包装器库Jota

1)连接到IOTA节点。您可以在https://nodes.iota.works处找到节点列表。另外,您可以设置自己的完整节点并使用它来代替外部节点。

final String protocol = "https";
final String url = "tuna.iotasalad.org"; 
final String port = "14265";
IotaAPI iotaServer = new IotaAPI.Builder().protocol(protocol).host(host).port(port).build();

2)将您的文本隐藏为小蜘蛛

String trytes = TrytesConverter.toTrytes("my text");

3)准备事务并将其发送到纠结

private static final String SEED = "IHDEENZYITYVYSPKAURUZAQKGVJERUZDJMYTANNZZGPZ9GKWTEOJJ9AAMXOGZNQLSNMFDSQOTZAEETA99";//just a random one
private static final int MIN_WEIGHT_MAGNITUDE = 14;
private static final int DEPTH = 9;
private static final int TAG = "mytag"; //optional

String tangleHash = prepareTransfer(createAddress(), trytes);

public String createAddress() throws ArgumentException {
     GetNewAddressResponse res = iotaServer.getNewAddress(SEED, 2, 0, false, 1, false);
     return res.getAddresses().get(0);
}

public String prepareTransfer(String address_seclevel_2, String trytes) throws ArgumentException {
    List<Transfer> transfers = new ArrayList<Transfer>();
    transfers.add(new Transfer(address_seclevel_2, 0, trytes, TAG));
    SendTransferResponse str = iotaServer.sendTransfer(SEED, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null,
                    null, false, false);
    if(str.getSuccessfully()!=null){
        //Transfer successfully! 

        for(Transaction tx: str.getTransactions()) {
            return tx.getHash();
        }

    }
    return "Handle error here. Something went wrong!";

}