Skip to main content

Transfers

This walkthrough covers how to sign a CBOR transaction through UKey Wallet Cardano Provider, submit the transaction, and complete more advanced transaction construction with Lucid or Mesh.


signature transaction

// transaction must be a CBOR-encoded hexadecimal string
const signedTx = await api.signTx(transactionCbor, partialSign);

// partialSign flag: boolean
// - false: sign every input controlled by the wallet
// - true: sign only the inputs explicitly marked as owned (useful for multisig)

console.log("Signed payload:", signedTx);

Submit transaction

// Submit the signed transaction
const txHash = await api.submitTx(signedTransactionCbor);
console.log("Tx hash:", txHash);

Complete transaction process

import {
TransactionBuilder,
TransactionBuilderConfigBuilder,
LinearFee,
BigNum,
Address,
TransactionOutput,
Value,
} from "@emurgo/cardano-serialization-lib-browser";

async function submitAdaTransfer(recipientAddress, amountLovelace) {
const api = await window.cardano.ukey.enable();

// Retrieve UTxO
const utxos = await api.getUtxos();
const changeAddress = await api.getChangeAddress();

// Build transaction
const txBuilder = TransactionBuilder.new(
TransactionBuilderConfigBuilder.new()
.fee_algo(LinearFee.new(BigNum.from_str("44"), BigNum.from_str("155381")))
.pool_deposit(BigNum.from_str("500000000"))
.key_deposit(BigNum.from_str("2000000"))
.max_value_size(5000)
.max_tx_size(16384)
.coins_per_utxo_byte(BigNum.from_str("4310"))
.build(),
);

// Collect input from UTxO
utxos.forEach((utxo) => {
// Add UTxO entries as inputs...
});

// Append an output
txBuilder.add_output(
TransactionOutput.new(
Address.from_bech32(recipientAddress),
Value.new(BigNum.from_str(amountLovelace)),
),
);

// Set the change address
txBuilder.add_change_if_needed(Address.from_bech32(changeAddress));

// Build transaction
const tx = txBuilder.build_tx();
const txCbor = Buffer.from(tx.to_bytes()).toString("hex");

// Sign with the wallet
const signedTxCbor = await api.signTx(txCbor, false);

// Submit the signed transaction
const txHash = await api.submitTx(signedTxCbor);
console.log("Tx hash:", txHash);

return txHash;
}

Use Lucid

Lucid can simplify the transaction construction and submission process:

npm install lucid-cardano
import { Lucid } from "lucid-cardano";

// Initialize Lucid with UKey Wallet
const lucid = await Lucid.new(
new Blockfrost("https://cardano-mainnet.blockfrost.io/api", "demo-api-key"),
"Mainnet",
);

// Open a connection to UKey Wallet
const api = await window.cardano.ukey.enable();
lucid.selectWallet(api);

// Send an ADA transfer
const tx = await lucid
.newTx()
.payToAddress("addr1demoexample...", { lovelace: 5000000n })
.complete();

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

console.log("Tx hash:", txHash);

Use Mesh

Mesh You can also use the browser wallet capability directly:

npm install @meshsdk/core
import { BrowserWallet, Transaction } from "@meshsdk/core";

// Open a connection to UKey Wallet
const wallet = await BrowserWallet.enable("ukey");

// Read wallet information
const balance = await wallet.getBalance();
const addresses = await wallet.getUsedAddresses();

// Note: Build and send transactions
const tx = new Transaction({ initiator: wallet }).sendLovelace(
"addr1demoexample...",
"5000000",
);

const unsignedTx = await tx.build();
const signedTx = await wallet.signTx(unsignedTx);
const txHash = await wallet.submitTx(signedTx);