我正在try 使用发送加密库发送比特币.它似乎要求私钥采用十六进制格式,但我的密钥的格式是"L3fKJ..."据我所知是WIF格式的?我想我需要使用ECPair来转换它,但它不起作用.
当前错误是"TypeError:ECPair.FromWIF不是一个函数".如果我使用Send-Crypto创建一个新的私有代码,则余额代码工作得很好.
如果有一种不使用Send-Crypto的更简单的方法,也会try 这样做.
const bitcoin = require('bitcoinjs-lib');
const ECPair = require('ecpair');
const CryptoAccount = require("send-crypto");
/* Load account from private key */
const privateKeyWIF = "L3fKJ...";
const keyPair = ECPair.fromWIF(privateKeyWIF);
const privateKey = keyPair.privateKey;
console.log(privateKey);
const account = new CryptoAccount(privateKey);
async function start() {
console.log(await account.address("BTC"));
console.log(await account.getBalance("BTC"));
console.log(await account.getBalance("BTC", {address:"bc1qe6..."}));
const balance = await account.getBalance("BTC");
await account.send("bc1qe6...", balance, "BTC", {
subtractFee: true,
});
};
start();