1

Using just HTML / PHP / Javascript and cardano-serialization, I have the connect wallet working. It shows the balance and stake address. So I have gotten that far.

My question is, how can I request the connected wallet for a chosen amount of ADA?

I do not want to use Mesh or any of those, just using Javascript.

Any and all input greatly appreciated!

EDIT: I am getting a lot of errors, can anyone tell me what else I can do to make this work correctly?

<script type="module">

import { Blockfrost, Lucid } from "https://unpkg.com/[email protected]/web/mod.js"; // NPM

const lucid = await Lucid.new(
  new Blockfrost("https://cardano-preview.blockfrost.io/api/v0", 
"mainnet..."),
"Preview",
);

// Assumes you are in a browser environment
const api = await window.cardano.nami.enable();
lucid.selectWallet(api);

const tx = await lucid.newTx()    

 .payToAddress("addr...", { lovelace: 5000000n })
  .complete();

const signedTx = await tx.sign().complete();

const txHash = await signedTx.submit();

console.log(txHash);

</script>

2 Answers 2

2

I recommend using Lucid for this:

import { Blockfrost, Lucid } from "lucid-cardano"; // NPM

const lucid = await Lucid.new(
  new Blockfrost("https://cardano-preview.blockfrost.io/api/v0", "<projectId>"),
  "Preview",
);

// Assumes you are in a browser environment
const api = await window.cardano.nami.enable();
lucid.selectWallet(api);

const tx = await lucid.newTx()
  .payToAddress("addr...", { lovelace: 5000000n })
  .complete();

const signedTx = await tx.sign().complete();

const txHash = await signedTx.submit();

console.log(txHash);

This piece of code (from the lucid github page) selects a wallet injected in the browser (in this case Nami) and creates a transaction using Lucid. It is quite easy to use and well documented!

1
  • I tried using this, can you look at the code i submitted and let me know what to change/add? Thanks.
    – lovetoshi
    Apr 29 at 19:58
0

I think you may be looking for this. https://cardano.stackexchange.com/a/7657/7159

Here is the official documentation. https://developers.cardano.org/docs/get-started/cardano-serialization-lib/generating-transactions/

Your Answer

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

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