-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
23 changed files
with
981 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mnemonic = 'thing organ quality use gift horn soldier acid guide roast ankle december elegant pattern doll' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"cells": [], | ||
"metadata": {}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"cells": [], | ||
"metadata": {}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,283 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "c354351e-9f77-4247-ab78-388c60c785e3", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Import dependencies\n", | ||
"import subprocess\n", | ||
"import json\n", | ||
"import os\n", | ||
"from dotenv import load_dotenv\n", | ||
"from bit import PrivateKeyTestnet\n", | ||
"from bit.network import NetworkAPI\n", | ||
"from bit import wif_to_key\n", | ||
"from web3 import Web3\n", | ||
"from web3.middleware import geth_poa_middleware\n", | ||
"from eth_account import Account" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "6b0da15f-496e-4f47-a953-402ac0c32ceb", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Load and set environment variables\n", | ||
"load_dotenv()\n", | ||
"mnemonic=os.getenv(\"mnemonic\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "6f001038-c449-472e-aa6d-acd799ee71d9", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"94" | ||
] | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# Make sure mnemonic loaded\n", | ||
"len(mnemonic)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "791d514f-1873-4450-86ab-03a86a8ad33b", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Import constants.py and necessary functions from bit and web3\n", | ||
"from constants import *" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "7646dae4-f33e-4a4b-95b3-fb0027a47a71", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"btc\n", | ||
"eth\n", | ||
"btc-test\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Make sure constants laoded\n", | ||
"print(BTC)\n", | ||
"print(ETH)\n", | ||
"print(BTCTEST)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "ecc9cf1c-e864-4332-9535-9b8a0e7a008e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"w3 = Web3(Web3.HTTPProvider(\"http://127.0.0.1:8545\"))\n", | ||
"w3.middleware_onion.inject(geth_poa_middleware, layer=0)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "a0ccc452-bb54-4c1c-9e01-f82d7e1eeea0", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Create a function called `derive_wallets`\n", | ||
"def derive_wallets(mnemonic, coin, numderive):\n", | ||
" command = 'php derive -g --mnemonic=\"'+str(mnemonic)+'\" --numderive=\"'+str(numderive)+'\" --coin=\"'+str(coin)+'\" --format=json'\n", | ||
" p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)\n", | ||
" output, err = p.communicate()\n", | ||
" p_status = p.wait()\n", | ||
" return json.loads(output)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "f97721cd-f7f0-4479-85c1-5288f80f5f6a", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[{'path': \"m/44'/60'/0'/0/0\",\n", | ||
" 'address': '0x45D09DD827d7E831EF60f4E8EF7EAA9b0b1edC66',\n", | ||
" 'xprv': 'xprvA3P4KWwQ2WuHB1vwFMC4nvBXBLoHw2zJLYhtvG4rX1aEf1A83gZDw7eQCamjPSzGF6jbr8KeJ7m3waYKBcNozYN365sja3YXRZ59hb9z38y',\n", | ||
" 'xpub': 'xpub6GNQj2UHrtTaPW1QMNj5A48FjNdnLVi9hmdVieUU5M7DXoVGbDsUUuxt3qS3Af3AkTezKgR7oYZgLC217Ffi4gSt7g1E9hZQAMsww1kARe3',\n", | ||
" 'privkey': '0xd36eb3f541c90f19705b3b4cfe878cfe3b7456b5ce1e76ace8dfacbccb6333c7',\n", | ||
" 'pubkey': '02a2b49f87fc935a35ffc6920dd735044e7f9e76134a321a6ce9c25433dd31f1a8',\n", | ||
" 'pubkeyhash': '3a7b0b58dc27f6ee3b1832bfc371abe2e3857672',\n", | ||
" 'index': 0},\n", | ||
" {'path': \"m/44'/60'/0'/0/1\",\n", | ||
" 'address': '0xF5a91a5685A147EfC55f6d5549Aa0fc5E37ABF20',\n", | ||
" 'xprv': 'xprvA3P4KWwQ2WuHFHjhz1JwNMw6VhgTESnYjsoaeKiCQxRTfDFG1Xfa1n8MUBXo95cBMWk76qdX8oyNUdjet6hDFeFNAMS4mGaPSsoQBNEgb4c',\n", | ||
" 'xpub': 'xpub6GNQj2UHrtTaTmpB62qwjVsq3jWwduWQ76jBSi7oyHxSY1aQZ4ypZaSqKTcXijirh1qdV2tL5knykjEzEnfaGUFR8EVUHQHt2mN935n3iR2',\n", | ||
" 'privkey': '0xcdd9936584730d93315c064dd59a16ca4ae6ee680b60ac459eb7b7abe88727df',\n", | ||
" 'pubkey': '035848f49e923c958c0de3e8b2609cc341b47b45ce162f35440fe36390f9a94659',\n", | ||
" 'pubkeyhash': 'f898e213ff8d8998428f2f0e3d768055bc1e7de6',\n", | ||
" 'index': 1},\n", | ||
" {'path': \"m/44'/60'/0'/0/2\",\n", | ||
" 'address': '0x497c1Ab6182b82E87ab146b1eb79C023cC60E210',\n", | ||
" 'xprv': 'xprvA3P4KWwQ2WuHHCSeAJP9q7kEzh3kYSkVEzcphWhF1hSicR7St8hQonKkotpa4djcwYp7rweSoiWcesztq6GAeZo3Nv5XrJMF3NArJXFFWme',\n", | ||
" 'xpub': 'xpub6GNQj2UHrtTaVgX7GKvACFgyYitEwuULcDYRVu6ra2yhVDSbRg1fMaeEfAgnvaeR4MEHtLnc76BgFiLkPcpXSFG7adR26g6EpcZTxPdisMe',\n", | ||
" 'privkey': '0x14a9d99906fe9919ae44bac0d4d11d1620df56305bafa9982c025e8ff7e84f02',\n", | ||
" 'pubkey': '0282b007eebf8a71e65e8543d02f7f465f4403e23f70f7ca7567c1deb47b02937f',\n", | ||
" 'pubkeyhash': '6bbb5f88d8116d344f1fb275ab4a9066543ee300',\n", | ||
" 'index': 2}]" | ||
] | ||
}, | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# Test derive_wallets function\n", | ||
"derive_wallets(mnemonic, ETH, 3)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "ddc5f966-a86b-489b-9dbb-daaf7ad86969", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Create a dictionary object called coins to store the output from `derive_wallets`.\n", | ||
"coins = {'eth':derive_wallets(mnemonic, ETH, 3), 'btc-test':derive_wallets(mnemonic, BTCTEST, 3)}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"id": "2c466122-c783-4f80-9e85-b14bf0a7103e", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"0xd36eb3f541c90f19705b3b4cfe878cfe3b7456b5ce1e76ace8dfacbccb6333c7\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Test calling a private key\n", | ||
"eth_privatekey = coins['eth'][0]['privkey']\n", | ||
"print(eth_privatekey)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"id": "7b09716c-88c0-402d-b631-beae4b5fdb6e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Create a function called `priv_key_to_account` that converts privkey strings to account objects.\n", | ||
"def priv_key_to_account(coin, priv_key):\n", | ||
" if coin == ETH:\n", | ||
" return Account.privateKeyToAccount(priv_key)\n", | ||
" if coin == BTCTEST:\n", | ||
" return PrivateKeyTestnet(priv_key)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"id": "c2b6474f-a904-4c35-ae7c-d814e781ecc6", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Create a function called `create_tx` that creates an unsigned transaction appropriate metadata.\n", | ||
"def create_tx(coin, account, to, amount):\n", | ||
" if coin == ETH:\n", | ||
" gasEstimate = w3.eth.estimateGas(\n", | ||
" {\"from\": account.address, \"to\": to, \"value\": amount}\n", | ||
" )\n", | ||
" return {\n", | ||
" \"from\": account.address,\n", | ||
" \"to\": to,\n", | ||
" \"value\": amount,\n", | ||
" \"gasPrice\": w3.eth.gasPrice,\n", | ||
" \"gas\": gasEstimate,\n", | ||
" \"nonce\": w3.eth.getTransactionCount(account.address),\n", | ||
" } \n", | ||
" if coin == BTCTEST:\n", | ||
" return PrivateKeyTestnet.prepare_transaction(account.address, [(to, amount, BTC)])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"id": "c5d449a0-4cdb-4791-83e2-ba21a615150c", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Create a function called `send_tx` that calls `create_tx`, signs and sends the transaction.\n", | ||
"def send_tx(coin, account, to, amount):\n", | ||
" if coin == ETH:\n", | ||
" tx = create_raw_tx(coin, account, to, amount)\n", | ||
" signed_tx = account.sign_transaction(tx)\n", | ||
" return w3.eth.sendRawTransaction(signed_tx.rawTransaction)\n", | ||
" if coin == BTCTEST:\n", | ||
" raw_tx = create_tx(coin, account, to, amount)\n", | ||
" signed = account.sign_transaction(raw_tx)\n", | ||
" return NetworkAPI.broadcast_tx_testnet(signed)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "06688395-0eb3-4975-80cf-4b28ab646e47", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.11" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
TERMINAL INPUTS/OUTPUTS: | ||
|
||
Windows PowerShell | ||
Try the new cross-platform PowerShell https://aka.ms/pscore6 | ||
PS C:\Users\badca> CD Blockchain-Tools/wallet | ||
PS C:\Users\badca\Blockchain-Tools\wallet> python | ||
Python 3.7.11 (default, Jul 27 2021, 09:42:29) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 | ||
Type "help", "copyright", "credits" or "license" for more information. | ||
>>> coins = {'eth':derive_wallets(mnemonic, ETH, 3), 'btc-test':derive_wallets(mnemonic, BTCTEST, 3)} | ||
>>> eth_priv_key = coins['eth'][0]['privkey'] | ||
>>> print(eth_priv_key) | ||
0xd36eb3f541c90f19705b3b4cfe878cfe3b7456b5ce1e76ace8dfacbccb6333c7 | ||
>>> btctest_priv_key = coins['btc-test'][0]['privkey'] | ||
>>> print(btctest_priv_key) | ||
cPaNtB94JGw9r8kMys5A9H4fF8dBj4UxwfPtykY2vH9QR5D7UbAK | ||
>>> priv_key_to_account(ETH, eth_priv_key) | ||
<eth_account.signers.local.LocalAccount object at 0x0000020114407F48> | ||
>>> priv_key_to_account(BTCTEST, btctest_priv_key) | ||
<PrivateKeyTestnet: mr8vMbDSEYC779zhdN2gYmuPfEz5hszBsc> | ||
>>> create_tx(BTCTEST, btc_acc,'mkHS9ne12qx9pS9VojpwU5xtRd4T7X7ZUt', 0.0001) | ||
'{"unspents":[{"amount":100000,"confirmations":4,"script":"76a914747e9d2520c294e04a684216b3ae42b13161d09c88ac","txid":"f13ffb8533106c8013e4142689ac273a94233f2530ef88b96fb089149b283d95","txindex":1,"type":"p2pkh","vsize":148,"segwit":false,"sequence":4294967295},{"amount":100000,"confirmations":1,"script":"76a914747e9d2520c294e04a684216b3ae42b13161d09c88ac","txid":"d4f4840bc1aeea56faf4dcfe294b99fdc3f63b13baeb8f56fa73665ec38a38b1","txindex":1,"type":"p2pkh","vsize":148,"segwit":false,"sequence":4294967295}],"outputs":[["mkHS9ne12qx9pS9VojpwU5xtRd4T7X7ZUt",10000],["mr8vMbDSEYC779zhdN2gYmuPfEz5hszBsc",186260]]}' | ||
>>> send_tx(BTCTEST, btc_acc,'mkHS9ne12qx9pS9VojpwU5xtRd4T7X7ZUt', 0.001) | ||
>>> derive_wallets(mnemonic, ETH, 3) | ||
[{'path': "m/44'/60'/0'/0/0", 'address': '0x45D09DD827d7E831EF60f4E8EF7EAA9b0b1edC66', 'xprv': 'xprvA3P4KWwQ248FjNdnLVi9hmdVieUU5M7DXoVGbDsUUuxt3qS3Af3AkTezKgR7oYZgLC217Ffi4gSt7g1E9hZQAMsww1kARe3', 'privkey': '0xd36eb31a8', 'pubkeyhash': '3a7b0b58dc27f6ee3b1832bfc371abe2e3857672', 'index': 0}, {'path': "m/44'/60'/0'/0/1", 'ad, 'pubkey': '035848f49e923c958c0de3e8b2609cc341b47b45ce162f35440fe36390f9a94659', 'pubkeyhash': 'f898e213ff8d': 'xprvA3P4KWwQ2WuHHCSeAJP9q7kEzh3kYSkVEzcphWhF1hSicR7St8hQonKkotpa4djcwYp7rweSoiWcesztq6GAeZo3Nv5XrJMF3NArJivkey': '0x14a9d99906fe9919ae44bac0d4d11d1620df56305bafa9982c025e8ff7e84f02', 'pubkey': '0282b007eebf8a71e65e | ||
VX5kfv8VnXMTmycznBRL5qkG5wnPeZSZMTZmMKTeNGiPLDwP3XhhsMr4DNR2WiuNw3xjKYzmZ68zd', 'privkey': 'cPaNtB94JGw9r8kMyESjWYc8', 'xpub': 'tpubDGnbC7F4L8C8APyASHcL414GVFf9TB5WmFBgbhYHi65FxruuBkezLVzRAQt7ryExsT7N2dYCQ7K49xxwRQ9BFKkxC6MLXxB8GpdULdUpm1P1B31Z2NyFp4NVubMaEwTPdYT9AQHTUU48euN4dj', 'xpub': 'tpubDGnbC7F4L8C8AyezrLZN8Wev9u3Sg1Js8tj4yt9', 'pubkey': '025662bd20f6157f80ecfa4379684babc2e04c9af97be41a7f53ba1d60db699492', 'pubkeyhash': 'ad738 | ||
>>> eth_acc = priv_key_to_account(ETH, eth_priv_key) | ||
>>> create_tx(ETH, eth_acc, '0x0dCAF04C1128F0b6519B6DE5ef14AFe39a01E612', 250 | ||
>>> send_tx(ETH, eth_acc, '0x0dCAF04C1128F0b6519B6DE5ef14AFe39a01E612', 250) | ||
HexBytes('0x15f3199a26dced1ff730c55e1a2269261c3d2d8ee490548f4f306f53981950cb') | ||
>>> w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:8545/0xd36eb3f541c90f19705b3b4cfe878cfe3b7456b5ce1e76ace8dfacbccb6333c7")) | ||
>>> w3.eth.getBalance("0x45D09DD827d7E831EF60f4E8EF7EAA9b0b1edC66") | ||
499999579999999999750 | ||
>>> send_tx(ETH, eth_acc, '0x0dCAF04C1128F0b6519B6DE5ef14AFe39a01E612', 250) | ||
HexBytes('0x7a9bacb0dd32becd4975d43b9616cbbfefc6a71fbe4cc8f78a4c0b427209b2fe') | ||
>>> w3.eth.getBalance("0x45D09DD827d7E831EF60f4E8EF7EAA9b0b1edC66") | ||
499999159999999999500 |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
BTC = 'btc' | ||
ETH = 'eth' | ||
BTCTEST = 'btc-test' |
Binary file not shown.
Oops, something went wrong.