0

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

4

1 回答 1

1

在缠结上存储文本数据并不难。以下是我基于缠结的应用程序的片段。我使用了 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)将您的文本转换为trytes

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!";

}
于 2019-02-09T21:20:13.343 回答