Skip to main content

ImportTapscript

ImportTapscript imports a Taproot script and internal key and adds the resulting Taproot output key as a watch-only output script into the wallet. For BIP-0086 style Taproot keys (no root hash commitment and no script spend path) use ImportPublicKey.

NOTE: Events (deposits/spends) for a key will only be detected by lnd if they happen after the import. Rescans to detect past events will be supported later on.

NOTE: Taproot keys imported through this RPC currently cannot be used for funding PSBTs. Only tracking the balance and UTXOs is currently supported.

Source: walletrpc/walletkit.proto

gRPC

rpc ImportTapscript (ImportTapscriptRequest) returns (ImportTapscriptResponse);

REST

HTTP MethodPath
POST /v2/wallet/tapscript/import

Code Samples

const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');

const GRPC_HOST = 'localhost:10009'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
const TLS_PATH = 'LND_DIR/tls.cert'

const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'walletrpc/walletkit.proto'], loaderOptions);
const walletrpc = grpc.loadPackageDefinition(packageDefinition).walletrpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new walletrpc.WalletKit(GRPC_HOST, creds);
let request = {
internal_public_key: <bytes>,
full_tree: <TapscriptFullTree>,
partial_reveal: <TapscriptPartialReveal>,
root_hash_only: <bytes>,
full_key_only: <bool>,
};
client.importTapscript(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "p2tr_address": <string>,
// }

Messages

walletrpc.ImportTapscriptRequest

Source: walletrpc/walletkit.proto

FieldgRPC TypeREST TypeREST Placement
internal_public_key
bytesstringbody
full_tree
TapscriptFullTreeobjectbody
partial_reveal
TapscriptPartialRevealobjectbody
root_hash_only
bytesstringbody
full_key_only
boolbooleanbody

walletrpc.ImportTapscriptResponse

Source: walletrpc/walletkit.proto

FieldgRPC TypeREST Type
p2tr_address
stringstring

Nested Messages

walletrpc.TapscriptFullTree

FieldgRPC TypeREST Type
all_leaves
TapLeaf[]array

walletrpc.TapLeaf

FieldgRPC TypeREST Type
leaf_version
uint32integer
script
bytesstring

walletrpc.TapscriptPartialReveal

FieldgRPC TypeREST Type
revealed_leaf
TapLeafobject
full_inclusion_proof
bytesstring