Skip to content
This repository was archived by the owner on Oct 24, 2022. It is now read-only.

Commit 6952824

Browse files
authored
feat: add lnd api SendCoins
1 parent 23c9233 commit 6952824

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/lnd.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,55 @@ class LND {
861861
return err(e);
862862
}
863863
}
864+
865+
/**
866+
* LND SendCoins
867+
* Send onchain transaction to a single output
868+
* @param address
869+
* @param amount
870+
* @param targetConf
871+
* @param feeRate
872+
* @param sendAll
873+
* @param label
874+
* @returns {Promise<Ok<lnrpc.SendCoinsResponse> | Err<unknown>>}
875+
*/
876+
async sendCoins(
877+
address: string,
878+
amount: number,
879+
targetConf?: number,
880+
feeRate?: number,
881+
sendAll?: boolean,
882+
label?: string
883+
): Promise<Result<lnrpc.SendCoinsResponse>> {
884+
try {
885+
const message = lnrpc.SendCoinsRequest.create();
886+
887+
message.addr = address;
888+
message.amount = amount;
889+
890+
if (targetConf) {
891+
message.targetConf = targetConf;
892+
}
893+
if (feeRate) {
894+
message.satPerVbyte = feeRate;
895+
}
896+
if (sendAll) {
897+
message.sendAll = sendAll;
898+
}
899+
if (label) {
900+
message.label = label;
901+
}
902+
903+
const serializedResponse = await this.grpc.sendCommand(
904+
EGrpcSyncMethods.SendCoins,
905+
lnrpc.SendCoinsRequest.encode(message).finish()
906+
);
907+
908+
return ok(lnrpc.SendCoinsResponse.decode(serializedResponse));
909+
} catch (e) {
910+
return err(e);
911+
}
912+
}
864913
}
865914

866915
export default new LND();

0 commit comments

Comments
 (0)