Once a web application is connected to Panda Wallet, it can prompt the user for permission to send BSV transactions on their behalf.
To send BSV to a Bitcoin address(es), you simply pass an array
of payment objects.
[
{
satoshis: number;
address?: string;
data?: string[]; // hex string array
script?: string; // hex string
inscription?: RawInscription; // see Provider Types
}
]
Sending a simple transaction to multiple recipients will look something like:
const wallet = initProvider(); // see "Detecting the Provider"
const paymentParams: = [
{
satoshis: 10000,
address: "18izL7Wtm2fx3ALoRY3MkY2VFSMjArP62D",
},
{
satoshis: 54000,
address: "1q6td54oZU8EPM1PwJcB1Z6upPyMe3Vy2",
},
];
try {
const { txid, rawtx } = await wallet.sendBsv(paymentParams);
console.log(txid);
// f2fc518036d96c956c30b995b4b0a70d6008b4b7ef666f7c913b2a79ab57d679
} catch (err) {
console.log(err);
}
Any change will always be sent back to the sender's Panda Wallet.
Adding Data
To send a data transaction, omit the address and simply specify the data payload as an array of hex encoded string values:
const data = ["hello", "world"]
const paymentParamts = [{
data: data.map((d) => Buffer.from(d).toString('hex)),
satoshis: 0,
}]
try {
const { txid, rawtx } = await wallet.sendBsv(paymentParams);
console.log(txid);
// a3fc518036d96c956c30b995b4b0a70d6008b4b7ef666f7c913b2a79ab57d67a
} catch (err) {
console.log(err);
}
Custom Scripts
In some cases you may need to specify an output script instead of an address or data payload:
const scriptHex = myscript.to_string()
const paymentParamts = [{
script: scriptHex,
satoshis: 0,
}]
try {
const { txid, rawtx } = await wallet.sendBsv(paymentParams);
console.log(txid);
// c4fc518036d96c956c30b995b4b0a70d6008b4b7ef666f7c913b2a79ab57d670
} catch (err) {
console.log(err);
}
Inscribe
While it's recommended to use the inscribe method, you can technically inscribe via sendBsv
as well.
const scriptHex = myscript.to_string()
const paymentParamts = [{
satoshis: 1,
address: "18izL7Wtm2fx3ALoRY3MkY2VFSMjArP62D",
inscription: {
base64Data: "UGFuZGEgaXMgYXdlc29tZSE=",
mimeType: "text/plain",
map: { app: "Cool app name", type: "ord", name: "Text #1" }
};
}]
try {
const { txid, rawtx } = await wallet.sendBsv(paymentParams);
console.log(txid);
// c4fc518036d96c956c30b995b4b0a70d6008b4b7ef666f7c913b2a79ab57d670
} catch (err) {
console.log(err);
}
Last updated