spark_transferToken
Use the spark_transferToken
method to send any BTKN token from the user’s wallet to a recipient’s Spark address.
Parameters
reciverSparkAddress
a string representing the destination Spark address Example: "sprt1pgssyuuuhnrrdjswal5c3s3rafw9w3y5dd4cjy3duxlf7hjzkp0rqx6dj6mrhu"
tokenIdentifier
a string representing the identifier of the Spark BTKN token
tokenAmount
a string representing the amount of the token to send (denominated based on token decimals - refer to spark_getBalance)
Example
import { request } from "sats-connect";
try {
const response = await request("spark_transferToken", {
receiverSparkAddress: "sprt1pgssyuuuhnrrdjswal5c3s3rafw9w3y5dd4cjy3duxlf7hjzkp0rqx6dj6mrhu",
tokenIdentifier: "btkn1qwertyuiopasdfghjklzxcvbnm1234567890abcdef", // Identifier of the Spark token
tokenAmount: 1000, // Amount to send (denominated based on token decimals)
});
if ("result" in response) {
console.log("Token transfer successful:", response.result.txid);
} else {
console.error("Token transfer failed:", response.error.message);
}
} catch (error) {
console.error("Unexpected error:", error);
}
What spark_transferToken does
This method initiates a token transfer on Spark using the selected token’s identifier. The user will:
Review the recipient, token name, and amount.
Approve the transaction in their Xverse wallet.
The transaction will be signed and broadcasted on the Spark network.
The spark_transferToken
method returns a Promise that resolves to the SparkTokenTransferResult
object:
txid
a hex-encoded string representing the ID of the BTKN transfer transaction on Spark
Last updated