内容简介:使用lucid在前端连接钱包nami,并发送ada。什么是lucid参考下面的链接。
准备工作:
- node/npm
- chrome插件钱包nami,(注意:没有firefox的版本,在firefox搜索到的nami钱包都是骗子)
- 测试币,cardano的测试网现在有三种,我们这里使用proprod,,水龙头。
- blockfrost注册账号,低于一定数量的请求数是免费的,不需要信用卡,用邮件注册。如果开发过ethers的都知道rpc,这个blockfrost就做这种作用
安装 lucid
npm install lucid-cardano
// import { Blockfrost, Lucid } from "https://deno.land/x/lucid@0.9.4/mod.ts"; Deno
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);
payToAddress函数的第一个参数是接收ada的钱包地址。 lovelace就是ada, 1,000,000个lovelace就是一个ada。 打印出来的txHash可以在preprod.cardanoscan.io/ 查证。
很简单,对吧,不比web3.js复杂。cardano还是很强的,由于是eutxo设计,所有nft mint都可以不需要智能合约。以后再介绍mint nft。