Node.js Bitcoin Development Tutorial: Create a Bitcoin Wallet

·

Creating a Bitcoin wallet using Node.js has never been more accessible. This comprehensive guide walks you through building a fully functional Bitcoin wallet on the Mixin Network using Node.js, enabling you to manage Bitcoin and other cryptocurrencies with ease. From setting up your environment to reading balances, sending payments, and withdrawing funds to external wallets, this tutorial covers every essential step for developers entering blockchain programming.

Whether you're building decentralized applications or integrating crypto payments into your platform, mastering wallet creation is a foundational skill. The Mixin Network offers fast, secure, and fee-free internal transactions—ideal for real-time applications.

Setting Up Your Mixin Network Account

Before creating a Bitcoin wallet, you must first generate a Mixin Network account. This process involves generating an RSA key pair and registering the public key with the network.

const { generateKeyPairSync } = require("crypto");

const { publicKey, privateKey } = generateKeyPairSync("rsa", {
  modulusLength: 1024,
  publicKeyEncoding: {
    type: "spki",
    format: "pem"
  },
  privateKeyEncoding: {
    type: "pkcs1",
    format: "pem"
  }
});

const publicKeyFormatted = publicKey
  .replace("-----BEGIN PUBLIC KEY-----", "")
  .replace("-----END PUBLIC KEY-----", "")
  .replace(/\n/g, "");

This code snippet creates a secure RSA key pair locally. The public key is then sent to the Mixin Network API to register a new user. Upon successful registration, the system returns critical credentials such as pin_token, session_id, and user_id, which are saved securely in a CSV file for future use.

👉 Discover how to securely generate and store cryptographic keys in your app

Creating a Bitcoin Wallet on Mixin Network

A newly created Mixin account does not automatically include a Bitcoin wallet. To initialize one, simply query the Bitcoin asset balance using the getUserAsset method:

const BTC_ASSET_ID = "c6d0c728-2624-429b-8e0d-d9d19b6592fa";
const assetInfo = await newUserClient.getUserAsset(BTC_ASSET_ID);

console.log("Bitcoin address is", assetInfo.public_key);
console.log("Bitcoin balance is", assetInfo.balance);
console.log("Bitcoin price in USD is", assetInfo.price_usd);

This call automatically provisions a Bitcoin wallet if it doesn't exist. The returned data includes:

Understanding Security and Private Keys

You might wonder: Where is the Bitcoin private key? On Mixin Network, private keys are managed via multi-signature security and are never exposed to users. Transactions require three components:

This architecture enhances security by eliminating direct access to private keys while maintaining full control over assets.

Supporting Multiple Cryptocurrencies

Mixin Network supports a wide range of digital assets beyond Bitcoin. By querying their respective asset IDs, you can enable wallets for Ethereum, EOS, Litecoin, and more. Here are some supported cryptocurrencies:

For EOS deposits, two fields are required:

Fee-Free Internal Transfers with Instant Confirmation

One of Mixin Network’s standout features is zero-fee, instant internal transactions. When transferring Bitcoin or any supported asset between Mixin users, no network fees apply, and confirmations occur within seconds.

To enable this functionality, set a PIN for your account:

await newUserClient.updatePin({
  oldPin: "",
  newPin: "123456"
});

const verifyPin = await newUserClient.verifyPin("123456");
console.log({ verifyPin });

Once configured, you can transfer funds programmatically:

const transferObj = {
  assetId: BTC_ASSET_ID,
  recipientId: MASTER_UUID,
  traceId: newUserClient.getUUID(),
  amount: "0.001",
  memo: "Test transfer"
};

await newUserClient.transferFromBot(transferObj);

After sending, verify the transaction by checking the recipient's balance.

👉 Learn how to implement instant crypto transfers in your Node.js app

Withdrawing Bitcoin to External Wallets

To move funds out of Mixin Network—such as to a cold wallet or exchange—you must first register the destination address.

Step 1: Add Withdrawal Address

Use the createWithdrawAddress API:

const withdrawAddress = await newUserClient.createWithdrawAddress({
  assetId: BTC_ASSET_ID,
  label: "Cold Wallet",
  publicKey: "14T129GTbXXPGXXvZzVaNLRFPeHXD1C25C"
});

This returns:

Step 2: Read Latest Fees

Always check updated fees before initiating withdrawal:

const addressList = await newUserClient.getWithdrawAddress(BTC_ASSET_ID);
console.log(addressList);

Step 3: Submit Withdrawal Request

Finalize the process with a signed withdrawal request:

const withdrawResult = await newUserClient.withdraw({
  addressId: withdrawAddress.address_id,
  assetId: BTC_ASSET_ID,
  amount: "0.01",
  memo: "Withdraw via Node.js"
});

console.log(withdrawResult);

Track the transaction status using any blockchain explorer.


Frequently Asked Questions

Q: Is it safe to store Bitcoin on Mixin Network?
A: Yes. While private keys are managed via multi-signature protocols and not visible to users, all transactions require authenticated PIN and cryptographic signatures, ensuring strong protection against unauthorized access.

Q: Are there fees when transferring Bitcoin inside Mixin Network?
A: No. Internal transfers between Mixin users are completely free and confirmed instantly—ideal for micropayments and high-frequency transactions.

Q: Can I create wallets for ERC20 tokens?
A: Absolutely. Since Mixin supports Ethereum, all ERC20 tokens can be managed similarly by using their respective asset IDs.

Q: How do I recover my wallet if I lose my credentials?
A: Always back up your private key, PIN, session ID, and user ID securely. Loss of these details may result in permanent loss of access.

Q: What’s the difference between deposit and withdrawal fees?
A: Deposits to Mixin are free. Withdrawals incur standard blockchain network fees to broadcast transactions externally.

Q: Can I automate regular Bitcoin payouts using this method?
A: Yes. This Node.js integration allows full automation of balance checks, transfers, and withdrawals—perfect for payment bots or payroll systems.


By following this guide, you now have the tools to build powerful cryptocurrency applications using Node.js and the Mixin Network. Whether you're managing Bitcoin wallets or enabling cross-chain transactions, these fundamentals lay the groundwork for scalable, secure blockchain integrations.

👉 Start building your own crypto wallet with advanced tools today