spacebudz / lucid

Lucid is a library, which allows you to create Cardano transactions and off-chain code for your Plutus contracts in JavaScript, Deno and Node.js.
https://lucid.spacebudz.io
MIT License
339 stars 139 forks source link

how to submit tranaction to send token to other address in nodejs backend code by using lucid-cardano? #187

Closed web3-literally closed 1 year ago

web3-literally commented 1 year ago

I have researched a lot to transfer token by using lucid-cardano, then didn't find reasonable answer yet, please help me how to transfer token by using lucid-cardano package, now in example folder, there is no code for that. Thanks

alessandrokonrad commented 1 year ago

To send assets you concatenate the policy id with the asset name:

const policyId = "abc....";
const name = "TestToken";
const unit = policyId + fromText(name);

const tx = await lucid
    .newTx()
    .payToAddress("addr...", { [unit]: 1n })
    .complete();