1

I am trying to build a transaction with the libary of cardano-client-lib (java sdk). Inorder to build a transaction one needs to provide an account object which can only be created with the mnemonic phase, which is clearly a problem.

I thought of using Nami wallet API as a walkaround, but seems unable to get the specific instance of the wallet in java. is there a way to build a transaction in java with nami api?

thanks.

4 Answers 4

1

Nami is a web wallet and injects its API into your website. It is not supposed to work with desktop applications but only with web apps. I recommend you to build your app with react + typescript + emurgo/cardano-serialization-lib-browser. That is how I built this minting app

1

Another option:

Transaction can be built in Java backend and then sent to Nami for signing.

Here's a sample code for Multi-sig token mint where

(Not exactly same but similar approach can be used for your scenario)

  1. Mint Transaction is built in Java backend
  2. Sign by Nami extension in the browser
  3. Send the witness back to Java backend
  4. Assemble transaction again with other witnesses in Java backend and submit the final transaction

MultiSigTokenMint With Java + Nami

0

I don't think you can get the wallet instance from Nami as the whole point of a wallet is to hide the private key and pass transactions visually to the user so that she can approve and submit them.

I would rather try the other way and look if your java library has methods to generate an unbalanced transaction that can be passed to the Nami wallet. Such a method would only need the wallet's UTxOs and the address of the recipient.

But I also have no clue on which libraries do this. It is very difficult at the moment to find anything useful on the subject.

0

I have done this function, don't know if it will help you.

Two projects are required:

cardano-client-examples https://github.com/zjavax/cardano-client-examples-zx/blob/main/src/main/java/cn/zjavax/BuildWithJavaBackend.java

public class BuildWithJavaBackend extends BaseTest {
    public static void main(String[] args) throws AddressExcepion, CborSerializationException, ApiException {
        new BuildWithJavaBackend().transfer();
        System.exit(1);
    }

    public void transfer() throws CborSerializationException, ApiException, AddressExcepion {
//        String senderMnemonic = "kit color frog trick speak employ suit sort bomb goddess jewel primary spoil fade person useless measure manage warfare reduce few scrub beyond era";
        String senderAddress = "addr_test1qqxnp3khzm7kcj9t23hskehat7428ghsenk0pfew4rqy5v9frnmht7uwrl073q4jvq20z82kh4rksyns540azhndqexqpvhgqr";
        String receiverAddress1 = "addr_test1qqwpl7h3g84mhr36wpetk904p7fchx2vst0z696lxk8ujsjyruqwmlsm344gfux3nsj6njyzj3ppvrqtt36cp9xyydzqzumz82";

        Output output1 = Output.builder()
                .address(receiverAddress1)
                .assetName(LOVELACE)
                .qty(adaToLovelace(1))
                .build();

        TxBuilder txBuilder = (output1.outputBuilder()
                .buildInputs(createFromSender(senderAddress, senderAddress))
        )
                .andThen(feeCalculator(senderAddress, 1))
                .andThen(adjustChangeOutput(senderAddress, 1));

        Transaction signedTransaction = TxBuilderContext.init(utxoSupplier, protocolParamsSupplier).build(txBuilder);

        System.out.println("txHexDraft=\"" +signedTransaction.serializeToHex()+"\"");

    }
}

cardano-walletconnector-demo enter image description here

The result of calling cc wallet: enter image description here

@Satya(don't know how @)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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