Python Bitcoin Tutorial: Create a Bitcoin Wallet, Check Balance, and Transfer Funds

ยท

Summary

This tutorial demonstrates how to create a Bitcoin wallet, check balances, and execute instant fee-free transfers using Python with Mixin Network.

Learning Objectives

Creating a Bitcoin Wallet with Mixin Network Python SDK

Prerequisites

You'll need a Mixin Network account. Create one with this simple code:

userInfo = mixinApiBotInstance.createUser(session_key.decode(),"Tom Bot")

This generates an RSA key pair locally, creates the account on Mixin Network, and outputs account information:

userInfo.get("data").get("pin_token"),
userInfo.get("data").get("session_id"),
userInfo.get("data").get("user_id"),

Successful account creation returns:

{"data": {
  "user_id": "2f25b669-15e7-392c-a1d5-fe7ba43bdf37",
  "identity_number": "0",
  "full_name": "Tom Bot",
  "session_id": "284c7b39-3284-4cf6-9354-87df30ec7d57",
  "pin_token": "g4upUgBXa8ATk7yxL6B94HgI4GV4sG4t8Wyn6uTu2Q2scH11UMQ5bYDb6Md+3LRQqRjEdRFcLlHijXGBihRweTaKTZjHQqolWbZcffesVIias6WppV/QMu4TzXCuKa5xpj3uhjL+yPyfWTLGUaVJTJN9n7PQmHSIUBXrovbfodk="
}}

๐Ÿ‘‰ Secure your account credentials now

Creating the Bitcoin Wallet

New accounts don't automatically include a Bitcoin wallet. Check the balance to create one:

def readAssetAddress(asset_id,isBTC=True):
    with open("new_users.csv", newline="") as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
            pin = row.pop()
            userid = row.pop()
            session_id = row.pop()
            pin_token = row.pop()
            private_key = row.pop()
            mixinApiNewUserInstance = generateMixinAPI(private_key,
            pin_token,
            session_id,
            userid,
            pin,"")
            btcInfo = mixinApiNewUserInstance.getAsset(asset_id)
            print(btcInfo)
            if isBTC:
                print("Account %s's Bitcoin wallet address is %s" %(userid,btcInfo.get("data").get("public_key")))

This returns Bitcoin asset details including the deposit address (public_key):

{
  "symbol": "BTC",
  "name": "Bitcoin",
  "balance": "0",
  "public_key": "12sJHR7HJPMt33KwSHyxQvYqGGUEbVGREf",
  "price_usd": "3879.88117389",
  "confirmations": 12
}

Supported Cryptocurrencies

CryptoUUID in Mixin Network
BTCc6d0c728-2624-429b-8e0d-d9d19b6592fa
ETH43d61dcd-e413-450d-80b8-101d5e903357
EOS6cfe566e-4aad-470b-8c9a-2fd35b49c68d
LTC76c802a2-7c88-447f-a93e-c29c9e5dd9c8

Transferring Bitcoin

Mixin Network enables instant, fee-free transfers between accounts:

  1. Set account PIN:

    pinInfo = mixinApiNewUserInstance.updatePin(PIN,"")
  2. Transfer Bitcoin:

    btcInfo = mixinApiBotInstance.transferTo(MASTER_UUID, BTC_ASSET_ID, AMOUNT, "")
  3. Verify balance:

    btcInfo = mixinApiNewUserInstance.getAsset(asset_id)
    print("Balance: %s" % btcInfo.get("data").get("balance"))

Withdrawing Bitcoin

To withdraw to external wallets:

  1. Add withdrawal address:

    btcInfo = mixinApiBotInstance.createAddress(BTC_ASSET_ID, "14T129GTbXXPGXXvZzVaNLRFPeHXD1C25C","BTC","","")
  2. Check withdrawal fee:

    addr_id = btcInfo.get("data").get("address_id")
    addrInfo = mixinApiBotInstance.getAddress(addr_id)
  3. Submit withdrawal:

    mixinApiBotInstance.withdrawals(btcInfo.get("data").get("address_id"),AMOUNT,"")

๐Ÿ‘‰ Learn advanced wallet security

FAQ

How secure is the Bitcoin wallet?

The wallet uses Mixin Network's multi-signature protection, keeping private keys secure while allowing transactions with proper RSA signatures.

What's the transfer speed?

Internal Mixin Network transfers confirm in 1 second with zero fees.

Can I add other cryptocurrencies?

Yes! The same process works for Ethereum, EOS, and other supported blockchains.

What are the withdrawal fees?

Current Bitcoin withdrawal fee is 0.0034802 BTC (subject to change).

How many confirmations are needed?

Bitcoin deposits require 12 confirmations on Mixin Network.