bitcoin rpc

This commit is contained in:
Ben Wilson
2023-06-10 11:57:49 -04:00
parent ff6adb8a65
commit 01b65b893a
7 changed files with 119 additions and 2 deletions
+33
View File
@@ -0,0 +1,33 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { RPCClient } from 'rpc-bitcoin';
@Injectable()
export class BitcoinRpcService {
private client: RPCClient;
constructor(configService: ConfigService) {
const url = configService.get('BITCOIN_RPC_URL');
const user = configService.get('BITCOIN_RPC_USER');
const pass = configService.get('BITCOIN_RPC_PASSWORD');
const port = parseInt(configService.get('BITCOIN_RPC_PORT'));
const timeout = parseInt(configService.get('BITCOIN_RPC_TIMEOUT'));
this.client = new RPCClient({ url, port, timeout, user, pass });
console.log('Bitcoin RPC connected');
}
public async getBlockTemplate() {
const result = await this.client.getblocktemplate({
template_request: {
rules: ['segwit'],
mode: 'template',
capabilities: ['serverlist', 'proposal']
}
});
}
}