-1

I was not able to find any tutorial or an example on manage data operation of Java sdk. I tried to build a sample using the Java API documentation. But it's too complicated. If anyone can show me how to do this I am really thankful. Sample code or if you can point out any tutorial or an example that would be fine also.

1

I'm not sure this is what you need but I have written some code for a Flutter plugin that might help to clear at least some things up: Check out this code snippet:

private SubmitTransactionResponse doManageData(final String seed, String name, String value) throws Exception {
        setServerAndNetwork();
        KeyPair keyPair = KeyPair.fromSecretSeed(seed);
        AccountResponse sourceAccount = server.accounts().account(keyPair.getAccountId());

        ManageDataOperation operation = new ManageDataOperation.Builder(name, value.getBytes())
                .setSourceAccount(keyPair.getAccountId())
                .build();
        Transaction transaction = new Transaction.Builder(sourceAccount, network)
                .addOperation(operation)
                .setTimeout(TIMEOUT_IN_SECONDS)
                .setOperationFee(100)
                .build();
        try {
            transaction.sign(keyPair);
            SubmitTransactionResponse response = server.submitTransaction(transaction);
            LOGGER.info("manageData: SubmitTransactionResponse: \uD83D\uDC99 Success? : " + response.isSuccess() + " \uD83D\uDC99 ");
            LOGGER.info(G.toJson(response));
            Log.d(TAG, response.isSuccess() ? "manageData transaction is SUCCESSFUL" : "manageData transaction failed");
            return response;
        } catch (Exception e) {
            String msg = "Failed to manageData: ";
            LOGGER.severe(msg + e.getMessage());
            throw new Exception(msg, e);
        }
    }
1
  • Many thanks for your support. I have figured it out thanks to your code snippet. Now it's working. – dev222 Apr 5 '20 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.