├── Chapter01 ├── 1.Python_warm_up.ipynb ├── 2.First_transaction.ipynb ├── 3.Relevant metrics.ipynb ├── 4.Relevant metrics II.ipynb └── w_btcabi.json ├── Chapter02 ├── 1.Transaction.ipynb ├── 2.Block.ipynb ├── 3.State.ipynb ├── 4.Data_sources.ipynb ├── ba_abi.json ├── readingev.py └── tether_abi.json ├── Chapter03 ├── .ipynb_checkpoints │ └── 2.News-checkpoint.ipynb ├── 1.Prices.ipynb ├── 2.News.ipynb ├── 3.Social.ipynb ├── tweets_100.csv └── tweets_df.csv ├── Chapter04 ├── 1.Games.ipynb ├── 2.Identity.ipynb ├── 3.Art.ipynb ├── ba_abi.json ├── ethregistrar_abi.json └── wolf_abi.json ├── Chapter05 ├── 1.Stablecoins.ipynb ├── 2.Liquidity_pool.ipynb ├── 3.Lending_borrowing.ipynb ├── 4.Bridges.ipynb ├── bridge_abi.json ├── ctoken_abi.json ├── erc20_abi.json └── pool_abi.json ├── Chapter06 ├── 1.Preparation.ipynb ├── 2.EDA.ipynb ├── 3.Outliers.ipynb └── witches.csv ├── Chapter07 ├── 1.ML_warmup.ipynb ├── 2.DL_warmup.ipynb └── kaggle.json ├── Chapter08 ├── .env ├── 1.Database_and_Preprocessing.ipynb ├── 2.Modeling.ipynb ├── app.py ├── chapter7_model.h5 ├── chat_gpt.py ├── clean_text.py ├── kaggle.json ├── preprocessed.csv └── text_tokenizer.json ├── Chapter09 ├── 1.style_transfer.ipynb └── 2.Leonardo_AI.ipynb ├── Chapter10 ├── 1.EDA and preprocessing.ipynb ├── 2.Building.ipynb ├── 3.Models.ipynb └── final.csv ├── Chapter11 ├── 1.Traditional_time_series_models.ipynb ├── 2.LSTM.ipynb ├── df transformation.png └── joint_news_df.csv ├── Chapter12 ├── 1.features.ipynb ├── 2.graphsage_node_classification.ipynb ├── community_gephi_filtered.jpg ├── influencers.csv ├── joint_binance_opensea.csv └── modularity2comunities.csv ├── LICENSE └── README.md /Chapter01/3.Relevant metrics.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "bb7e540b", 6 | "metadata": {}, 7 | "source": [ 8 | "## Imports\n", 9 | "\n", 10 | "Import the web3, datetime libraries. The web3 library will be used to connect to the Ethereum blockchain and retrieve transaction data. The datetime library is used to manipulate time data. The pandas library will be used to store the transaction data in a dataframe." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "7c7807de", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "from web3 import Web3\n", 21 | "from datetime import datetime" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "id": "5bc192be", 27 | "metadata": {}, 28 | "source": [ 29 | "## Connection\n", 30 | "\n", 31 | "Use the web3 library to connect to the Ethereum blockchain and retrieve transaction data using the Infura URL provided. The `web3.isConnected()` method will be used to check if the connection was successful." 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 2, 37 | "id": "d678abfc", 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "data": { 42 | "text/plain": [ 43 | "True" 44 | ] 45 | }, 46 | "execution_count": 2, 47 | "metadata": {}, 48 | "output_type": "execute_result" 49 | } 50 | ], 51 | "source": [ 52 | "infura_url= 'https://mainnet.infura.io/v3/[YOUR INFURA KEY]'\n", 53 | "web3= Web3(Web3.HTTPProvider (infura_url))\n", 54 | "web3.isConnected()" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "id": "b091a60f", 60 | "metadata": {}, 61 | "source": [ 62 | "## Block Height\n", 63 | "\n", 64 | "Print the latest Ethereum block number stored in the variable 'latest'. This will allow the user to see the most recent block number and use it to retrieve transaction data from the Ethereum blockchain." 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 3, 70 | "id": "d44dee2c", 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [ 74 | "latest = web3.eth.blockNumber" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 4, 80 | "id": "467c52ba", 81 | "metadata": {}, 82 | "outputs": [ 83 | { 84 | "name": "stdout", 85 | "output_type": "stream", 86 | "text": [ 87 | "The latest block is: 15652876\n" 88 | ] 89 | } 90 | ], 91 | "source": [ 92 | "print (\"The latest block is: \", latest)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "id": "d77e8b15", 98 | "metadata": {}, 99 | "source": [ 100 | "## Time\n", 101 | "\n", 102 | "Retrieve the timestamp of the latest Ethereum block stored in the variable 'latest'. This will allow the user to see the timestamp of the most recent block and use it to retrieve transaction data from the Ethereum blockchain when needed as an input.\n", 103 | "\n", 104 | "Timestamp is expressed in unix timestamp format and the following code convert it to a readable date format." 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": 5, 110 | "id": "a7166d43", 111 | "metadata": {}, 112 | "outputs": [ 113 | { 114 | "data": { 115 | "text/plain": [ 116 | "1664622047" 117 | ] 118 | }, 119 | "execution_count": 5, 120 | "metadata": {}, 121 | "output_type": "execute_result" 122 | } 123 | ], 124 | "source": [ 125 | "block_timestamp= web3.eth.get_block(latest).timestamp\n", 126 | "block_timestamp" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 6, 132 | "id": "7234fa81", 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "name": "stdout", 137 | "output_type": "stream", 138 | "text": [ 139 | "2022-10-01 11:00:47\n" 140 | ] 141 | } 142 | ], 143 | "source": [ 144 | "block_timestamp = int(block_timestamp)\n", 145 | "print(datetime.utcfromtimestamp(block_timestamp).strftime('%Y-%m-%d %H:%M:%S'))" 146 | ] 147 | } 148 | ], 149 | "metadata": { 150 | "kernelspec": { 151 | "display_name": "Python 3 (ipykernel)", 152 | "language": "python", 153 | "name": "python3" 154 | }, 155 | "language_info": { 156 | "codemirror_mode": { 157 | "name": "ipython", 158 | "version": 3 159 | }, 160 | "file_extension": ".py", 161 | "mimetype": "text/x-python", 162 | "name": "python", 163 | "nbconvert_exporter": "python", 164 | "pygments_lexer": "ipython3", 165 | "version": "3.8.13" 166 | } 167 | }, 168 | "nbformat": 4, 169 | "nbformat_minor": 5 170 | } 171 | -------------------------------------------------------------------------------- /Chapter01/w_btcabi.json: -------------------------------------------------------------------------------- 1 | "[{\"constant\":true,\"inputs\":[],\"name\":\"mintingFinished\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_token\",\"type\":\"address\"}],\"name\":\"reclaimToken\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"unpause\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"mint\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"burn\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"claimOwnership\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"paused\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_subtractedValue\",\"type\":\"uint256\"}],\"name\":\"decreaseApproval\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"finishMinting\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_addedValue\",\"type\":\"uint256\"}],\"name\":\"increaseApproval\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"pendingOwner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"Pause\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"Unpause\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"burner\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Burn\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"Mint\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"MintFinished\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"previousOwner\",\"type\":\"address\"}],\"name\":\"OwnershipRenounced\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"}]" -------------------------------------------------------------------------------- /Chapter02/1.Transaction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "dd48c80b", 6 | "metadata": {}, 7 | "source": [ 8 | "### Introduction:\n", 9 | "This notebook corresponds to Chapter 2. The primary objective of this notebook is to provide practical code examples that complement the explanations given in the chapter. Here, we will delve into the different components of a transaction executed on the Ethereum blockchain.\n", 10 | "\n", 11 | "By following the provided steps, you will develop a comprehensive understanding of each part of a transaction and learn how to access and analyze them. This hands-on approach will enhance your proficiency in working with transaction data and enable you to navigate and interpret Ethereum transactions effectively.\n", 12 | "\n", 13 | "#### Imports\n", 14 | "\n", 15 | "Import the necesary libraries to run the notebook." 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "id": "29992777", 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "from web3 import Web3\n", 26 | "from datetime import datetime\n", 27 | "import pandas as pd\n", 28 | "import json" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "id": "5cea09ff", 34 | "metadata": {}, 35 | "source": [ 36 | "#### Connection\n", 37 | "Connect to the Ethereum blockchain using the web3 library and the Infura service. Check if the connection is successful by calling the `web3.isConnected()` method." 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 2, 43 | "id": "63698425", 44 | "metadata": {}, 45 | "outputs": [ 46 | { 47 | "data": { 48 | "text/plain": [ 49 | "True" 50 | ] 51 | }, 52 | "execution_count": 2, 53 | "metadata": {}, 54 | "output_type": "execute_result" 55 | } 56 | ], 57 | "source": [ 58 | "infura_url= 'https://mainnet.infura.io/v3/[YOUR API KEY]'\n", 59 | "web3= Web3(Web3.HTTPProvider (infura_url))\n", 60 | "web3.isConnected()" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "id": "6c3f7f5c", 66 | "metadata": {}, 67 | "source": [ 68 | "# Dissecting Transaction\n", 69 | "\n", 70 | "We will define one address and one transaction to use as example. " 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 3, 76 | "id": "13b19029", 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "address= web3.toChecksumAddress(\"0x1ad91ee08f21be3de0ba2ba6918e714da6b45836\")\n", 81 | "transaction= '0x032ed60363beb809a2b9c9790bb7dadd83b743040945a087aeecbe9e6b2dc2af'" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "id": "954a38da", 87 | "metadata": {}, 88 | "source": [ 89 | "* Nonce\n", 90 | "\n", 91 | "#### Retrieve the Account nonce\n", 92 | "\n", 93 | "We can query directly the address and it retrieve the number up to the latest block." 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": 4, 99 | "id": "b3ccfb7f", 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "data": { 104 | "text/plain": [ 105 | "3460174" 106 | ] 107 | }, 108 | "execution_count": 4, 109 | "metadata": {}, 110 | "output_type": "execute_result" 111 | } 112 | ], 113 | "source": [ 114 | "next_nonce= web3.eth.getTransactionCount(address)\n", 115 | "next_nonce" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "id": "c3008531", 121 | "metadata": {}, 122 | "source": [ 123 | "Or we can query a transaction, that will provide the situation of the source address at the moment of that transaction. " 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 5, 129 | "id": "b8b4954c", 130 | "metadata": {}, 131 | "outputs": [ 132 | { 133 | "data": { 134 | "text/plain": [ 135 | "3460171" 136 | ] 137 | }, 138 | "execution_count": 5, 139 | "metadata": {}, 140 | "output_type": "execute_result" 141 | } 142 | ], 143 | "source": [ 144 | "transaction_nonce= web3.eth.get_transaction(transaction).nonce\n", 145 | "transaction_nonce" 146 | ] 147 | }, 148 | { 149 | "cell_type": "markdown", 150 | "id": "e05b685c", 151 | "metadata": {}, 152 | "source": [ 153 | "* Gas\n", 154 | "\n", 155 | "#### Retrieve Transaction Gas Price\n", 156 | "Retrieve the gas price for a given transaction using the `web3.eth.get_transaction()` method specifying the `gas price` property. " 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 6, 162 | "id": "aeab5f6a", 163 | "metadata": {}, 164 | "outputs": [ 165 | { 166 | "data": { 167 | "text/plain": [ 168 | "19209576968" 169 | ] 170 | }, 171 | "execution_count": 6, 172 | "metadata": {}, 173 | "output_type": "execute_result" 174 | } 175 | ], 176 | "source": [ 177 | "gasPrice= web3.eth.get_transaction(transaction).gasPrice\n", 178 | "gasPrice" 179 | ] 180 | }, 181 | { 182 | "cell_type": "markdown", 183 | "id": "0f62c2b5", 184 | "metadata": {}, 185 | "source": [ 186 | "#### Retrieve Transaction Gas limit\n", 187 | "Retrieve the gas price for a given transaction using the `web3.eth.get_transaction()` method specifying the `gas` property. " 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 7, 193 | "id": "81921057", 194 | "metadata": {}, 195 | "outputs": [ 196 | { 197 | "data": { 198 | "text/plain": [ 199 | "100000" 200 | ] 201 | }, 202 | "execution_count": 7, 203 | "metadata": {}, 204 | "output_type": "execute_result" 205 | } 206 | ], 207 | "source": [ 208 | "gaslimit= web3.eth.get_transaction(transaction).gas\n", 209 | "gaslimit" 210 | ] 211 | }, 212 | { 213 | "cell_type": "markdown", 214 | "id": "faebc030", 215 | "metadata": {}, 216 | "source": [ 217 | "#### Retrieve Transaction Gas Used\n", 218 | "Retrieve the gas price for a given transaction using the `web3.eth.get_transaction()` method specifying the `gasUsed` property. " 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": 8, 224 | "id": "68e64704", 225 | "metadata": {}, 226 | "outputs": [ 227 | { 228 | "data": { 229 | "text/plain": [ 230 | "21000" 231 | ] 232 | }, 233 | "execution_count": 8, 234 | "metadata": {}, 235 | "output_type": "execute_result" 236 | } 237 | ], 238 | "source": [ 239 | "gasUsed= web3.eth.getTransactionReceipt (transaction).gasUsed\n", 240 | "gasUsed" 241 | ] 242 | }, 243 | { 244 | "cell_type": "markdown", 245 | "id": "5007bfee", 246 | "metadata": {}, 247 | "source": [ 248 | "* To\n", 249 | "\n", 250 | "#### Retrieve Transaction Recipient\n", 251 | "Retrieve the transaction recipient for a given transaction using the `web3.eth.get_transaction()` method specifying the `to` property. " 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": 9, 257 | "id": "86563628", 258 | "metadata": {}, 259 | "outputs": [ 260 | { 261 | "data": { 262 | "text/plain": [ 263 | "'0x3c16183c1C0E28F1a0cB9F8ee4b21D0Db208cA46'" 264 | ] 265 | }, 266 | "execution_count": 9, 267 | "metadata": {}, 268 | "output_type": "execute_result" 269 | } 270 | ], 271 | "source": [ 272 | "recipient= web3.eth.get_transaction(transaction).to\n", 273 | "recipient" 274 | ] 275 | }, 276 | { 277 | "cell_type": "markdown", 278 | "id": "16d416f8", 279 | "metadata": {}, 280 | "source": [ 281 | "* From\n", 282 | "\n", 283 | "#### Retrieve Transaction Sender\n", 284 | "Retrieve the transaction sender for a given transaction using the `web3.eth.get_transaction()` method specifying the `gas price` property. " 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": null, 290 | "id": "63de0c18", 291 | "metadata": {}, 292 | "outputs": [], 293 | "source": [ 294 | "sender= web3.eth.get_transaction(transaction)[\"from\"]\n", 295 | "sender" 296 | ] 297 | }, 298 | { 299 | "cell_type": "markdown", 300 | "id": "ec1171cd", 301 | "metadata": {}, 302 | "source": [ 303 | "* Value\n", 304 | "\n", 305 | "#### Retrieving Transaction Value\n", 306 | "Retrieve the value transferred in a given transaction using the `web3.eth.get_transaction()` method specifying the `value` property. The value of the transaction is expressed in wei, which can be converted to ether by multiplying it by `10**-18` or with `web3.fromWei('value','ether')`" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": 10, 312 | "id": "90090943", 313 | "metadata": {}, 314 | "outputs": [ 315 | { 316 | "data": { 317 | "text/plain": [ 318 | "48.0" 319 | ] 320 | }, 321 | "execution_count": 10, 322 | "metadata": {}, 323 | "output_type": "execute_result" 324 | } 325 | ], 326 | "source": [ 327 | "value= web3.eth.get_transaction(transaction).value\n", 328 | "value*10**-18" 329 | ] 330 | }, 331 | { 332 | "cell_type": "markdown", 333 | "id": "c030cab9", 334 | "metadata": {}, 335 | "source": [ 336 | "* Data\n", 337 | "\n", 338 | "#### Retrieve Transaction Input\n", 339 | "Retrieve the input data in a given transaction using the `web3.eth.get_transaction()` method specifying the `input` property." 340 | ] 341 | }, 342 | { 343 | "cell_type": "code", 344 | "execution_count": 11, 345 | "id": "fdd2b011", 346 | "metadata": {}, 347 | "outputs": [ 348 | { 349 | "data": { 350 | "text/plain": [ 351 | "'0x'" 352 | ] 353 | }, 354 | "execution_count": 11, 355 | "metadata": {}, 356 | "output_type": "execute_result" 357 | } 358 | ], 359 | "source": [ 360 | "data= web3.eth.get_transaction(transaction).input\n", 361 | "data" 362 | ] 363 | }, 364 | { 365 | "cell_type": "markdown", 366 | "id": "7fb947dc", 367 | "metadata": {}, 368 | "source": [ 369 | "#### Decode Transaction Input\n", 370 | "\n", 371 | "We will connect the ABI, the smart contract address and the input data resulting of using the `web3.eth.get_transaction()` method. " 372 | ] 373 | }, 374 | { 375 | "cell_type": "code", 376 | "execution_count": 12, 377 | "id": "2432c647", 378 | "metadata": {}, 379 | "outputs": [], 380 | "source": [ 381 | "transaction_ba='0xb3827bb3cca1a693ec69edb744755f64d8ff8c90f89f69cbfbfafd17b0083159'" 382 | ] 383 | }, 384 | { 385 | "cell_type": "code", 386 | "execution_count": 13, 387 | "id": "ac88f456", 388 | "metadata": {}, 389 | "outputs": [ 390 | { 391 | "data": { 392 | "text/plain": [ 393 | "'0xa723533e0000000000000000000000000000000000000000000000000000000000000001'" 394 | ] 395 | }, 396 | "execution_count": 13, 397 | "metadata": {}, 398 | "output_type": "execute_result" 399 | } 400 | ], 401 | "source": [ 402 | "data_ba= web3.eth.get_transaction(transaction_ba).input\n", 403 | "data_ba" 404 | ] 405 | }, 406 | { 407 | "cell_type": "code", 408 | "execution_count": 14, 409 | "id": "0e5d15e0", 410 | "metadata": {}, 411 | "outputs": [], 412 | "source": [ 413 | "bored_ape= web3.eth.get_transaction(transaction_ba)" 414 | ] 415 | }, 416 | { 417 | "cell_type": "code", 418 | "execution_count": 15, 419 | "id": "bdfbe92d", 420 | "metadata": {}, 421 | "outputs": [], 422 | "source": [ 423 | "sc_address=\"0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D\"\n", 424 | "with open (\"./ba_abi.json\") as f:\n", 425 | " abi= json.load (f)" 426 | ] 427 | }, 428 | { 429 | "cell_type": "code", 430 | "execution_count": 16, 431 | "id": "b715fb0e", 432 | "metadata": {}, 433 | "outputs": [], 434 | "source": [ 435 | "baContract = web3.eth.contract(address=sc_address, abi=abi)" 436 | ] 437 | }, 438 | { 439 | "cell_type": "markdown", 440 | "id": "8162734e", 441 | "metadata": {}, 442 | "source": [ 443 | "The method `decode_function_input ()` will decode the function input from the bored_ape dictionary. " 444 | ] 445 | }, 446 | { 447 | "cell_type": "code", 448 | "execution_count": 17, 449 | "id": "18b61cac", 450 | "metadata": {}, 451 | "outputs": [ 452 | { 453 | "name": "stdout", 454 | "output_type": "stream", 455 | "text": [ 456 | " parameters: {'numberOfTokens': 1}\n" 457 | ] 458 | } 459 | ], 460 | "source": [ 461 | "function, parameters = baContract.decode_function_input(bored_ape[\"input\"])\n", 462 | "print (function, 'parameters: ',parameters )" 463 | ] 464 | }, 465 | { 466 | "cell_type": "markdown", 467 | "id": "346ce303", 468 | "metadata": {}, 469 | "source": [ 470 | "* Log events\n", 471 | "\n", 472 | "#### Decoding Events\n", 473 | "Create a list of events listed in the the object baContract. Loop through the abi_events list and create a dictionary called event_abi_hex. The dictionary will contain the event name as the key and the event ABI in hexadecimal format as the value. " 474 | ] 475 | }, 476 | { 477 | "cell_type": "code", 478 | "execution_count": 18, 479 | "id": "496c038a", 480 | "metadata": {}, 481 | "outputs": [], 482 | "source": [ 483 | "abi_events = [abi for abi in baContract.abi if abi[\"type\"] == \"event\"]\n", 484 | "event_abi_hex = {}\n", 485 | "for event in abi_events:\n", 486 | " name = event[\"name\"]\n", 487 | " inputs = \",\".join([param[\"type\"] for param in event[\"inputs\"]])\n", 488 | " event_abi_human = f\"{name}({inputs})\"\n", 489 | " event_abi_hex[name] = web3.toHex(web3.keccak(text=event_abi_human))" 490 | ] 491 | }, 492 | { 493 | "cell_type": "markdown", 494 | "id": "83c62858", 495 | "metadata": {}, 496 | "source": [ 497 | "Retrieve the transaction receipt for the transaction_ba and loop through the logs in the receipt. For each log, it will get the event in hexadecimal format from the first topic and then compare it to the event_abi_hex dictionary. If a match is found, it will decode the log using `processReceipt(tx_receipt)` " 498 | ] 499 | }, 500 | { 501 | "cell_type": "code", 502 | "execution_count": 19, 503 | "id": "b9055c7a", 504 | "metadata": {}, 505 | "outputs": [ 506 | { 507 | "data": { 508 | "text/plain": [ 509 | "(AttributeDict({'args': AttributeDict({'from': '0x0000000000000000000000000000000000000000',\n", 510 | " 'to': '0x9909017A0F637380af916257D05c3e7dD2F6c68a',\n", 511 | " 'tokenId': 6633}),\n", 512 | " 'event': 'Transfer',\n", 513 | " 'logIndex': 124,\n", 514 | " 'transactionIndex': 321,\n", 515 | " 'transactionHash': HexBytes('0xb3827bb3cca1a693ec69edb744755f64d8ff8c90f89f69cbfbfafd17b0083159'),\n", 516 | " 'address': '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D',\n", 517 | " 'blockHash': HexBytes('0x26537966b001e26c3c960bfb619d1af5fdd4d04c54596fb50a3a94d73bf66a69'),\n", 518 | " 'blockNumber': 12347114}),)" 519 | ] 520 | }, 521 | "execution_count": 19, 522 | "metadata": {}, 523 | "output_type": "execute_result" 524 | } 525 | ], 526 | "source": [ 527 | "tx_receipt = web3.eth.getTransactionReceipt(transaction_ba)\n", 528 | "decoded_logs = []\n", 529 | "for log in tx_receipt['logs']:\n", 530 | " event_hex = web3.toHex(log['topics'][0])\n", 531 | " event_name = None\n", 532 | " for name, hex_value in event_abi_hex.items():\n", 533 | " if hex_value == event_hex:\n", 534 | " event_name = name\n", 535 | " break\n", 536 | " if event_name is not None:\n", 537 | " decoded_log = baContract.events[event_name]().processReceipt(tx_receipt)\n", 538 | " decoded_logs.append(decoded_log)\n", 539 | "decoded_logs" 540 | ] 541 | } 542 | ], 543 | "metadata": { 544 | "kernelspec": { 545 | "display_name": "Python 3 (ipykernel)", 546 | "language": "python", 547 | "name": "python3" 548 | }, 549 | "language_info": { 550 | "codemirror_mode": { 551 | "name": "ipython", 552 | "version": 3 553 | }, 554 | "file_extension": ".py", 555 | "mimetype": "text/x-python", 556 | "name": "python", 557 | "nbconvert_exporter": "python", 558 | "pygments_lexer": "ipython3", 559 | "version": "3.8.13" 560 | } 561 | }, 562 | "nbformat": 4, 563 | "nbformat_minor": 5 564 | } 565 | -------------------------------------------------------------------------------- /Chapter02/2.Block.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "1db013fc", 6 | "metadata": {}, 7 | "source": [ 8 | "### Introduction:\n", 9 | "This notebook corresponds to Chapter 2. The primary objective of this notebook is to provide practical code examples that complement the explanations given in the chapter. Here, we will focus on demonstrating the information retrieved from the Ethereum blockchain using the `Web3` library.\n", 10 | "\n", 11 | "By following the provided steps, you will gain hands-on experience in accessing and analyzing block-related information. This practical approach aims to enhance your understanding of the concepts discussed in the chapter and strengthen your proficiency in working with Ethereum data. \n", 12 | "\n", 13 | "#### Imports\n", 14 | "\n", 15 | "Import the necessary libraries to run the notebook." 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "id": "4f5d9d92", 22 | "metadata": {}, 23 | "outputs": [], 24 | "source": [ 25 | "from web3 import Web3\n", 26 | "from datetime import datetime\n", 27 | "import pandas as pd" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "id": "4d3109dd", 33 | "metadata": {}, 34 | "source": [ 35 | "#### Connection to the Ethereum Network\n", 36 | "Connect to the Ethereum network using the Web3 library. The `Web3` object is initialized with the URL of the Ethereum node provided by Infura. The `web3.isConnected()` method is used to check if the connection is successful." 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 2, 42 | "id": "a5099b18", 43 | "metadata": {}, 44 | "outputs": [ 45 | { 46 | "data": { 47 | "text/plain": [ 48 | "True" 49 | ] 50 | }, 51 | "execution_count": 2, 52 | "metadata": {}, 53 | "output_type": "execute_result" 54 | } 55 | ], 56 | "source": [ 57 | "infura_url= 'https://mainnet.infura.io/v3/[YOUR API KEY]'\n", 58 | "web3= Web3(Web3.HTTPProvider (infura_url))\n", 59 | "web3.isConnected()" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "id": "e2c929af", 65 | "metadata": {}, 66 | "source": [ 67 | "## Analysis of a block\n", 68 | "#### Retrieve the Parent Hash\n", 69 | "Retrieve the parent hash of a given block using the `web3.eth.getBlock()` method. The `block_identifier` argument is used to specify the block number and the `parentHash` property is specified. " 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 15, 75 | "id": "6df15356", 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "data": { 80 | "text/plain": [ 81 | "HexBytes('0x9b930569ef6794eb018d54d6a0768f4445f757d62ddffa79698cd5c1fea04b31')" 82 | ] 83 | }, 84 | "execution_count": 15, 85 | "metadata": {}, 86 | "output_type": "execute_result" 87 | } 88 | ], 89 | "source": [ 90 | "parent= web3.eth.getBlock(block_identifier= 15813288).parentHash\n", 91 | "parent" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "id": "1c4c84fb", 97 | "metadata": {}, 98 | "source": [ 99 | "#### Retrieving the Fee recipient \n", 100 | "Retrieve the validator (post-Merge) or miner (pre-Merge) or fee recipient of a given block using the `web3.eth.getBlock()` method, specifying the `miner` property. " 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 9, 106 | "id": "72379046", 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "data": { 111 | "text/plain": [ 112 | "'0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990'" 113 | ] 114 | }, 115 | "execution_count": 9, 116 | "metadata": {}, 117 | "output_type": "execute_result" 118 | } 119 | ], 120 | "source": [ 121 | "beneficiary= web3.eth.getBlock(block_identifier= 15813288).miner\n", 122 | "beneficiary" 123 | ] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "id": "87d77396", 128 | "metadata": {}, 129 | "source": [ 130 | "#### Retrieving the Difficulty\n", 131 | "Retrieve the difficulty of a given block using the `web3.eth.getBlock()` method, specifying the block number and the `difficulty` property. In this case we analyze a block that was added post- 'The Merge'." 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 20, 137 | "id": "1d73c9e4", 138 | "metadata": {}, 139 | "outputs": [ 140 | { 141 | "data": { 142 | "text/plain": [ 143 | "0" 144 | ] 145 | }, 146 | "execution_count": 20, 147 | "metadata": {}, 148 | "output_type": "execute_result" 149 | } 150 | ], 151 | "source": [ 152 | "difficulty= web3.eth.getBlock(block_identifier= 15813288).difficulty\n", 153 | "difficulty" 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "id": "5af312b7", 159 | "metadata": {}, 160 | "source": [ 161 | "In this case we analyze the last block previous to the 'The Merge'. " 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": 35, 167 | "id": "be7e1eaa", 168 | "metadata": {}, 169 | "outputs": [ 170 | { 171 | "data": { 172 | "text/plain": [ 173 | "11055787484078698" 174 | ] 175 | }, 176 | "execution_count": 35, 177 | "metadata": {}, 178 | "output_type": "execute_result" 179 | } 180 | ], 181 | "source": [ 182 | "difficulty= web3.eth.getBlock(block_identifier= 15537393).difficulty\n", 183 | "difficulty" 184 | ] 185 | }, 186 | { 187 | "cell_type": "markdown", 188 | "id": "d4fb5f3c", 189 | "metadata": {}, 190 | "source": [ 191 | "#### Retrieve the totalDifficulty\n", 192 | "Calculate the total difficulty of a given block using the `web3.eth.getBlock()` method, specifying the block number and the `totalDifficulty` property. In this case we analyze a block that was added post - 'The Merge'. " 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": 21, 198 | "id": "b6a22d19", 199 | "metadata": {}, 200 | "outputs": [ 201 | { 202 | "data": { 203 | "text/plain": [ 204 | "58750003716598352816469" 205 | ] 206 | }, 207 | "execution_count": 21, 208 | "metadata": {}, 209 | "output_type": "execute_result" 210 | } 211 | ], 212 | "source": [ 213 | "difficulty_total= web3.eth.getBlock(block_identifier= 15813288).totalDifficulty\n", 214 | "difficulty_total" 215 | ] 216 | }, 217 | { 218 | "cell_type": "markdown", 219 | "id": "a781b2d0", 220 | "metadata": {}, 221 | "source": [ 222 | "In this case we analyze the last block previous to 'The Merge'. This is the last block where `totalDifficulty` changed because the consensus changed from PoW to PoS." 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 36, 228 | "id": "cb9c7b95", 229 | "metadata": {}, 230 | "outputs": [ 231 | { 232 | "data": { 233 | "text/plain": [ 234 | "58750003716598352816469" 235 | ] 236 | }, 237 | "execution_count": 36, 238 | "metadata": {}, 239 | "output_type": "execute_result" 240 | } 241 | ], 242 | "source": [ 243 | "difficulty_total= web3.eth.getBlock(block_identifier= 15537393).totalDifficulty\n", 244 | "difficulty_total" 245 | ] 246 | }, 247 | { 248 | "cell_type": "markdown", 249 | "id": "54b6e481", 250 | "metadata": {}, 251 | "source": [ 252 | "#### Retrieve the Block Number\n", 253 | "Retrieve the block number of a given block using the `web3.eth.getBlock()` method. If we do not use the `block_identifier` argument, it will show the latest block number. " 254 | ] 255 | }, 256 | { 257 | "cell_type": "code", 258 | "execution_count": 22, 259 | "id": "65c4127f", 260 | "metadata": {}, 261 | "outputs": [ 262 | { 263 | "data": { 264 | "text/plain": [ 265 | "15813288" 266 | ] 267 | }, 268 | "execution_count": 22, 269 | "metadata": {}, 270 | "output_type": "execute_result" 271 | } 272 | ], 273 | "source": [ 274 | "number= web3.eth.getBlock(block_identifier= 15813288).number\n", 275 | "number" 276 | ] 277 | }, 278 | { 279 | "cell_type": "markdown", 280 | "id": "5bfb633e", 281 | "metadata": {}, 282 | "source": [ 283 | "#### Retrieve the Block Size\n", 284 | "Retrieve the size of a given block using the `web3.eth.getBlock()` method, specifying the block number and the `size` property." 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": 23, 290 | "id": "7b26d8d0", 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "data": { 295 | "text/plain": [ 296 | "63648" 297 | ] 298 | }, 299 | "execution_count": 23, 300 | "metadata": {}, 301 | "output_type": "execute_result" 302 | } 303 | ], 304 | "source": [ 305 | "size= web3.eth.getBlock(block_identifier= 15813288).size\n", 306 | "size " 307 | ] 308 | }, 309 | { 310 | "cell_type": "markdown", 311 | "id": "2ef7920c", 312 | "metadata": {}, 313 | "source": [ 314 | "#### Retrieve the Gas Limit\n", 315 | "Retrieve the gas limit of a given block using the `web3.eth.getBlock()` method, specifying the block number and the `gasLimit` property." 316 | ] 317 | }, 318 | { 319 | "cell_type": "code", 320 | "execution_count": 24, 321 | "id": "6ba9aa35", 322 | "metadata": {}, 323 | "outputs": [ 324 | { 325 | "data": { 326 | "text/plain": [ 327 | "30000000" 328 | ] 329 | }, 330 | "execution_count": 24, 331 | "metadata": {}, 332 | "output_type": "execute_result" 333 | } 334 | ], 335 | "source": [ 336 | "g_limit= web3.eth.getBlock(block_identifier= 15813288).gasLimit\n", 337 | "g_limit " 338 | ] 339 | }, 340 | { 341 | "cell_type": "markdown", 342 | "id": "d1f93fb0", 343 | "metadata": {}, 344 | "source": [ 345 | "#### Retrieve the Gas Used\n", 346 | "Retrieve the gas used of a given block using the `web3.eth.getBlock()` method, specifying the block number and the `gasUsed` property." 347 | ] 348 | }, 349 | { 350 | "cell_type": "code", 351 | "execution_count": 25, 352 | "id": "591db9ba", 353 | "metadata": {}, 354 | "outputs": [ 355 | { 356 | "data": { 357 | "text/plain": [ 358 | "13247169" 359 | ] 360 | }, 361 | "execution_count": 25, 362 | "metadata": {}, 363 | "output_type": "execute_result" 364 | } 365 | ], 366 | "source": [ 367 | "g_used= web3.eth.getBlock(block_identifier= 15813288).gasUsed \n", 368 | "g_used" 369 | ] 370 | }, 371 | { 372 | "cell_type": "markdown", 373 | "id": "f426c8b4", 374 | "metadata": {}, 375 | "source": [ 376 | "#### Calculating the Percentage of Gas Used\n", 377 | "Calculate the percentage of gas used of a given block by dividing `gas used` by `gas limit`." 378 | ] 379 | }, 380 | { 381 | "cell_type": "code", 382 | "execution_count": 31, 383 | "id": "09078726", 384 | "metadata": {}, 385 | "outputs": [ 386 | { 387 | "data": { 388 | "text/plain": [ 389 | "44.15723" 390 | ] 391 | }, 392 | "execution_count": 31, 393 | "metadata": {}, 394 | "output_type": "execute_result" 395 | } 396 | ], 397 | "source": [ 398 | "percentage_used= (g_used/g_limit)*100\n", 399 | "percentage_used" 400 | ] 401 | }, 402 | { 403 | "cell_type": "markdown", 404 | "id": "5af9dab2", 405 | "metadata": {}, 406 | "source": [ 407 | "#### Retrieve the Base Fee Per Gas\n", 408 | "Retrieve the base fee per gas of a given block using the `web3.eth.getBlock()` method, specifying the block number and `baseFeePerGas` property. " 409 | ] 410 | }, 411 | { 412 | "cell_type": "code", 413 | "execution_count": 44, 414 | "id": "c8db1b02", 415 | "metadata": {}, 416 | "outputs": [ 417 | { 418 | "data": { 419 | "text/plain": [ 420 | "15649778689" 421 | ] 422 | }, 423 | "execution_count": 44, 424 | "metadata": {}, 425 | "output_type": "execute_result" 426 | } 427 | ], 428 | "source": [ 429 | "g_fee= web3.eth.getBlock(block_identifier= 15813288).baseFeePerGas \n", 430 | "g_fee" 431 | ] 432 | }, 433 | { 434 | "cell_type": "markdown", 435 | "id": "c53cb68c", 436 | "metadata": {}, 437 | "source": [ 438 | "#### Retrieve the Block time\n", 439 | "Retrieve the timestamp of a given block using the `web3.eth.getBlock()` method, specifying the block number and the `timestamp` property. We also convert it to a human-readable format using the `datetime.utcfromtimestamp()` method. " 440 | ] 441 | }, 442 | { 443 | "cell_type": "code", 444 | "execution_count": 34, 445 | "id": "2155e11a", 446 | "metadata": {}, 447 | "outputs": [ 448 | { 449 | "name": "stdout", 450 | "output_type": "stream", 451 | "text": [ 452 | "1666557983\n", 453 | "2022-10-23 20:46:23\n" 454 | ] 455 | } 456 | ], 457 | "source": [ 458 | "timestamp= web3.eth.getBlock(block_identifier= 15813288).timestamp\n", 459 | "print (timestamp)\n", 460 | "print(datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S'))" 461 | ] 462 | }, 463 | { 464 | "cell_type": "markdown", 465 | "id": "ce0b546a", 466 | "metadata": {}, 467 | "source": [ 468 | "#### Retrieving the Nonce\n", 469 | "Retrieve the nonce of a given block using the `web3.eth.getBlock()` method, specifying the block number and the `nonce` property. In this case we analyze a block added post 'The Merge'" 470 | ] 471 | }, 472 | { 473 | "cell_type": "code", 474 | "execution_count": 37, 475 | "id": "f473dfb7", 476 | "metadata": {}, 477 | "outputs": [ 478 | { 479 | "data": { 480 | "text/plain": [ 481 | "HexBytes('0x0000000000000000')" 482 | ] 483 | }, 484 | "execution_count": 37, 485 | "metadata": {}, 486 | "output_type": "execute_result" 487 | } 488 | ], 489 | "source": [ 490 | "nonce= web3.eth.getBlock(block_identifier= 15813288).nonce\n", 491 | "nonce" 492 | ] 493 | }, 494 | { 495 | "cell_type": "markdown", 496 | "id": "ccbd965c", 497 | "metadata": {}, 498 | "source": [ 499 | "This is the nonce of the last block mined previous to 'The Merge'." 500 | ] 501 | }, 502 | { 503 | "cell_type": "code", 504 | "execution_count": 38, 505 | "id": "a353a302", 506 | "metadata": {}, 507 | "outputs": [ 508 | { 509 | "data": { 510 | "text/plain": [ 511 | "HexBytes('0x62a3ee77461d4fc9')" 512 | ] 513 | }, 514 | "execution_count": 38, 515 | "metadata": {}, 516 | "output_type": "execute_result" 517 | } 518 | ], 519 | "source": [ 520 | "nonce= web3.eth.getBlock(block_identifier= 15537393).nonce\n", 521 | "nonce" 522 | ] 523 | }, 524 | { 525 | "cell_type": "markdown", 526 | "id": "a86d34ee", 527 | "metadata": {}, 528 | "source": [ 529 | "#### Counting the Transactions of a Block\n", 530 | "Count the number of transactions in a given block using the `web3.eth.getBlock()` method, specifying the block number and the `transactions` property. In this case, the last block before 'The Merge' only had one transaction. " 531 | ] 532 | }, 533 | { 534 | "cell_type": "code", 535 | "execution_count": 41, 536 | "id": "91e79778", 537 | "metadata": {}, 538 | "outputs": [ 539 | { 540 | "data": { 541 | "text/plain": [ 542 | "1" 543 | ] 544 | }, 545 | "execution_count": 41, 546 | "metadata": {}, 547 | "output_type": "execute_result" 548 | } 549 | ], 550 | "source": [ 551 | "transactions_list= len (web3.eth.getBlock(block_identifier= 15537393).transactions)\n", 552 | "transactions_list" 553 | ] 554 | }, 555 | { 556 | "cell_type": "markdown", 557 | "id": "d206122b", 558 | "metadata": {}, 559 | "source": [ 560 | "The block in the cell below had 112 transactions. " 561 | ] 562 | }, 563 | { 564 | "cell_type": "code", 565 | "execution_count": 42, 566 | "id": "106721aa", 567 | "metadata": {}, 568 | "outputs": [ 569 | { 570 | "data": { 571 | "text/plain": [ 572 | "112" 573 | ] 574 | }, 575 | "execution_count": 42, 576 | "metadata": {}, 577 | "output_type": "execute_result" 578 | } 579 | ], 580 | "source": [ 581 | "transactions_list= len (web3.eth.getBlock(block_identifier=15813288).transactions)\n", 582 | "transactions_list" 583 | ] 584 | } 585 | ], 586 | "metadata": { 587 | "kernelspec": { 588 | "display_name": "Python 3 (ipykernel)", 589 | "language": "python", 590 | "name": "python3" 591 | }, 592 | "language_info": { 593 | "codemirror_mode": { 594 | "name": "ipython", 595 | "version": 3 596 | }, 597 | "file_extension": ".py", 598 | "mimetype": "text/x-python", 599 | "name": "python", 600 | "nbconvert_exporter": "python", 601 | "pygments_lexer": "ipython3", 602 | "version": "3.8.13" 603 | } 604 | }, 605 | "nbformat": 4, 606 | "nbformat_minor": 5 607 | } 608 | -------------------------------------------------------------------------------- /Chapter02/3.State.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "4a27a2b1", 6 | "metadata": {}, 7 | "source": [ 8 | "### Introduction:\n", 9 | "This notebook corresponds to Chapter 2. The primary objective of this notebook is to provide practical code examples that complement the explanations given in the chapter. Specifically, in this space we will focus on extracting data from smart contract functions at the latest block or any specific block in time.\n", 10 | "\n", 11 | "By following the provided steps, you will gain hands-on experience in interacting with smart contracts and retrieving reliable data.\n", 12 | "\n", 13 | "#### Imports\n", 14 | "Import the necesary libraries to run the notebook. " 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "id": "40e1369c", 21 | "metadata": {}, 22 | "outputs": [], 23 | "source": [ 24 | "from web3 import Web3\n", 25 | "from ens import ENS\n", 26 | "from datetime import datetime\n", 27 | "import pandas as pd\n", 28 | "import json" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "id": "b775675f", 34 | "metadata": {}, 35 | "source": [ 36 | "#### Connection\n", 37 | "Connect to the Ethereum blockchain using the web3 library and the Infura service. Check if the connection is successful by calling the `web3.isConnected()` method." 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 2, 43 | "id": "23a5414a", 44 | "metadata": {}, 45 | "outputs": [ 46 | { 47 | "data": { 48 | "text/plain": [ 49 | "True" 50 | ] 51 | }, 52 | "execution_count": 2, 53 | "metadata": {}, 54 | "output_type": "execute_result" 55 | } 56 | ], 57 | "source": [ 58 | "infura_url= 'https://mainnet.infura.io/v3/[YOUR API KEY]'\n", 59 | "web3= Web3(Web3.HTTPProvider (infura_url))\n", 60 | "ns = ENS.fromWeb3(web3)\n", 61 | "web3.isConnected()" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "id": "c7fa9907", 67 | "metadata": {}, 68 | "source": [ 69 | "#### Provide Contract Details\n", 70 | "Load the ABI stored in the `ba_abi.json` file. Use the web3 library to create a contract instance from the Ethereum address stored in the sc_address variable and the ABI stored in the ba_abi.json file." 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 3, 76 | "id": "74d150bd", 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "sc_address=\"0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D\"\n", 81 | "with open (\"./ba_abi.json\") as f:\n", 82 | " abi= json.load (f)" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 4, 88 | "id": "cf5caef1", 89 | "metadata": {}, 90 | "outputs": [], 91 | "source": [ 92 | "baContract = web3.eth.contract(address=sc_address, abi=abi)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "id": "03284c81", 98 | "metadata": {}, 99 | "source": [ 100 | "Investigate all the contract functions" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 5, 106 | "id": "115b933a", 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "data": { 111 | "text/plain": [ 112 | "[,\n", 113 | " ,\n", 114 | " ,\n", 115 | " ,\n", 116 | " ,\n", 117 | " ,\n", 118 | " ,\n", 119 | " ,\n", 120 | " ,\n", 121 | " ,\n", 122 | " ,\n", 123 | " ,\n", 124 | " ,\n", 125 | " ,\n", 126 | " ,\n", 127 | " ,\n", 128 | " ,\n", 129 | " ,\n", 130 | " ,\n", 131 | " ,\n", 132 | " ,\n", 133 | " ,\n", 134 | " ,\n", 135 | " ,\n", 136 | " ,\n", 137 | " ,\n", 138 | " ,\n", 139 | " ,\n", 140 | " ,\n", 141 | " ,\n", 142 | " ,\n", 143 | " ,\n", 144 | " ,\n", 145 | " ,\n", 146 | " ,\n", 147 | " ,\n", 148 | " ]" 149 | ] 150 | }, 151 | "execution_count": 5, 152 | "metadata": {}, 153 | "output_type": "execute_result" 154 | } 155 | ], 156 | "source": [ 157 | "baContract.all_functions()" 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "id": "50b17383", 163 | "metadata": {}, 164 | "source": [ 165 | "#### Retrieve total number of Apes\n", 166 | "Retrieve the maximum number of apes minted by the contract by calling the function `MAX_APES()`. " 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 6, 172 | "id": "909adc25", 173 | "metadata": {}, 174 | "outputs": [ 175 | { 176 | "name": "stdout", 177 | "output_type": "stream", 178 | "text": [ 179 | "Max apes are: 10000\n" 180 | ] 181 | } 182 | ], 183 | "source": [ 184 | "print (\"Max apes are: \", baContract.functions.MAX_APES().call())" 185 | ] 186 | }, 187 | { 188 | "cell_type": "markdown", 189 | "id": "a2a4d82b", 190 | "metadata": {}, 191 | "source": [ 192 | "#### Retrieve Owner of APE 6633\n", 193 | "Retrieve the owner of APE 6633 by calling the function `ownerOf()`. " 194 | ] 195 | }, 196 | { 197 | "cell_type": "code", 198 | "execution_count": 7, 199 | "id": "a5622167", 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "name": "stdout", 204 | "output_type": "stream", 205 | "text": [ 206 | "The owner of APE 6633: 0xC4505dB8CC490767fA6f4b6f0F2bDd668B357A5D\n" 207 | ] 208 | } 209 | ], 210 | "source": [ 211 | "print (\"The owner of APE 6633: \", baContract.functions.ownerOf(6633).call())" 212 | ] 213 | }, 214 | { 215 | "cell_type": "markdown", 216 | "id": "47ecef13", 217 | "metadata": {}, 218 | "source": [ 219 | "#### Retrieve previous Owner of APE 6633 \n", 220 | "Retrieve the owner of APE 6633 by calling the function `ownerOf()` and providing a block previous to the last transfer. " 221 | ] 222 | }, 223 | { 224 | "cell_type": "code", 225 | "execution_count": 8, 226 | "id": "98f242bc", 227 | "metadata": {}, 228 | "outputs": [ 229 | { 230 | "name": "stdout", 231 | "output_type": "stream", 232 | "text": [ 233 | "The owner of APE 6633: 0xDE2b87d1539904f4b37E98C0d5CE383E890006eF\n" 234 | ] 235 | } 236 | ], 237 | "source": [ 238 | "print (\"The owner of APE 6633: \", baContract.functions.ownerOf(6633).call(block_identifier=14044021))" 239 | ] 240 | }, 241 | { 242 | "cell_type": "markdown", 243 | "id": "d58c53a1", 244 | "metadata": {}, 245 | "source": [ 246 | "#### Who is the previous Owner of APE 6633\n", 247 | "Use the `ns.name()` method from the ENS library to retrieve the domain name of a the previous owner's address. " 248 | ] 249 | }, 250 | { 251 | "cell_type": "code", 252 | "execution_count": 3, 253 | "id": "d442f573", 254 | "metadata": {}, 255 | "outputs": [ 256 | { 257 | "name": "stdout", 258 | "output_type": "stream", 259 | "text": [ 260 | "The previous owner of the Ape 6633 was: tommykethvault.eth\n" 261 | ] 262 | } 263 | ], 264 | "source": [ 265 | "domain = ns.name('0xDE2b87d1539904f4b37E98C0d5CE383E890006eF')\n", 266 | "print (\"The previous owner of the Ape 6633 was:\", domain)" 267 | ] 268 | } 269 | ], 270 | "metadata": { 271 | "kernelspec": { 272 | "display_name": "Python 3 (ipykernel)", 273 | "language": "python", 274 | "name": "python3" 275 | }, 276 | "language_info": { 277 | "codemirror_mode": { 278 | "name": "ipython", 279 | "version": 3 280 | }, 281 | "file_extension": ".py", 282 | "mimetype": "text/x-python", 283 | "name": "python", 284 | "nbconvert_exporter": "python", 285 | "pygments_lexer": "ipython3", 286 | "version": "3.8.13" 287 | } 288 | }, 289 | "nbformat": 4, 290 | "nbformat_minor": 5 291 | } 292 | -------------------------------------------------------------------------------- /Chapter02/ba_abi.json: -------------------------------------------------------------------------------- 1 | "[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"name\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"maxNftSupply\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"saleStart\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"approved\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"ApprovalForAll\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"BAYC_PROVENANCE\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"MAX_APES\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"REVEAL_TIMESTAMP\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"apePrice\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"baseURI\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"emergencySetStartingIndexBlock\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"flipSaleState\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"getApproved\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"maxApePurchase\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"numberOfTokens\",\"type\":\"uint256\"}],\"name\":\"mintApe\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"ownerOf\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"reserveApes\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"saleIsActive\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"setApprovalForAll\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"baseURI\",\"type\":\"string\"}],\"name\":\"setBaseURI\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"provenanceHash\",\"type\":\"string\"}],\"name\":\"setProvenanceHash\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"revealTimeStamp\",\"type\":\"uint256\"}],\"name\":\"setRevealTimestamp\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"setStartingIndex\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"startingIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"startingIndexBlock\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"tokenByIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"tokenOfOwnerByIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"tokenURI\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"withdraw\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" -------------------------------------------------------------------------------- /Chapter02/readingev.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import json 3 | from web3 import Web3 4 | from websockets import connect 5 | import winsound 6 | 7 | #set up the alarm 8 | frequency = 2500 9 | duration = 1000 10 | 11 | #connect to the node 12 | infura_ws_url = 'wss://mainnet.infura.io/ws/v3/[YOUR API KEY]' 13 | infura_http_url = 'https://mainnet.infura.io/v3/[YOUR API KEY]' 14 | web3 = Web3(Web3.HTTPProvider(infura_http_url)) 15 | 16 | #details of the smart contract we are tracking 17 | tether_account = web3.toChecksumAddress('0xdAC17F958D2ee523a2206206994597C13D831ec7') 18 | with open ("./tether_abi.json") as f: 19 | tether_abi= json.load (f) 20 | tetherContract = web3.eth.contract(address=tether_account, abi=tether_abi) 21 | 22 | async def get_event(): 23 | async with connect(infura_ws_url) as ws: 24 | await ws.send('{"jsonrpc": "2.0", "id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}') 25 | subscription_response = await ws.recv() 26 | print(subscription_response) 27 | 28 | while True: 29 | try: 30 | message = await asyncio.wait_for(ws.recv(), timeout=15) 31 | response = json.loads(message) 32 | txHash = response['params']['result'] 33 | tx = web3.eth.get_transaction(txHash) 34 | if tx.to == tether_account: 35 | winsound.Beep(frequency, duration) 36 | print({ 37 | "hash": txHash, 38 | "from": tx["from"], 39 | "value_eth": web3.fromWei(tx["value"], 'ether'), 40 | "function": tetherContract.decode_function_input(tx["input"])[0], 41 | "value_usdt": (tetherContract.decode_function_input(tx["input"])[1]['_value'])*10**-6 42 | }) 43 | pass 44 | except: 45 | pass 46 | 47 | if __name__ == "__main__": 48 | loop = asyncio.get_event_loop() 49 | while True: 50 | loop.run_until_complete(get_event()) 51 | -------------------------------------------------------------------------------- /Chapter02/tether_abi.json: -------------------------------------------------------------------------------- 1 | "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_upgradedAddress\",\"type\":\"address\"}],\"name\":\"deprecate\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"deprecated\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_evilUser\",\"type\":\"address\"}],\"name\":\"addBlackList\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"upgradedAddress\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"balances\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"maximumFee\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"_totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"unpause\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_maker\",\"type\":\"address\"}],\"name\":\"getBlackListStatus\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"address\"}],\"name\":\"allowed\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"paused\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"who\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"pause\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getOwner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"newBasisPoints\",\"type\":\"uint256\"},{\"name\":\"newMaxFee\",\"type\":\"uint256\"}],\"name\":\"setParams\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"issue\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"redeem\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"remaining\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"basisPointsRate\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"isBlackListed\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_clearedUser\",\"type\":\"address\"}],\"name\":\"removeBlackList\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"MAX_UINT\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_blackListedUser\",\"type\":\"address\"}],\"name\":\"destroyBlackFunds\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_initialSupply\",\"type\":\"uint256\"},{\"name\":\"_name\",\"type\":\"string\"},{\"name\":\"_symbol\",\"type\":\"string\"},{\"name\":\"_decimals\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"Issue\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"Redeem\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"newAddress\",\"type\":\"address\"}],\"name\":\"Deprecate\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"feeBasisPoints\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"maxFee\",\"type\":\"uint256\"}],\"name\":\"Params\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_blackListedUser\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_balance\",\"type\":\"uint256\"}],\"name\":\"DestroyedBlackFunds\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_user\",\"type\":\"address\"}],\"name\":\"AddedBlackList\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_user\",\"type\":\"address\"}],\"name\":\"RemovedBlackList\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"Pause\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"Unpause\",\"type\":\"event\"}]" -------------------------------------------------------------------------------- /Chapter03/.ipynb_checkpoints/2.News-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "74090563", 6 | "metadata": {}, 7 | "source": [ 8 | "## Imports\n", 9 | "\n", 10 | "Import the `requests` library to retrieve data from the CryptoPanic URL and `pandas` to manipulate it." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "4e6a475b", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "import requests\n", 21 | "import pandas as pd" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "id": "5191b50c", 27 | "metadata": {}, 28 | "source": [ 29 | "## CryptoPanic\n", 30 | "\n", 31 | "Use the `requests` library to retrieve the news titles from CryptoPanic. " 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 2, 37 | "id": "974ea147", 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "url= 'https://cryptopanic.com/api/v1/posts/?auth_token=[YOUR API KEY]¤cies=BTC&kind=news'\n", 42 | "response = requests.get(url)\n", 43 | "data= response.json()" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 3, 49 | "id": "a5606fe2", 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "name": "stdout", 54 | "output_type": "stream", 55 | "text": [ 56 | "Kazakhstan Lawmakers Pass New Bitcoin Mining Bills\n", 57 | "This Week in Coins: Bitcoin and Ethereum Flat Again, Axie Infinity Sees Rare Jump\n", 58 | "Texas Senator Ted Cruz Is a Fan of Bitcoin and Crypto Mining\n", 59 | "Whales Move Over 275 Million XRP Amid Price Surge\n", 60 | "Bitcoin, Ethereum Technical Analysis: BTC, ETH Consolidate to Start the Weekend\n", 61 | "FTX’s Dent on Crypto Could Last a While\n", 62 | "Bitcoin bulls protect $17K as trader eyes key China BTC price catalyst\n", 63 | "Crypto.com Crypto Exchange Provides Proof of Reserves After Panic by Investors – Here’s What You Need to Know\n", 64 | "Bitcoin Sees Another Threat? - Elon Musk Just Might Be Hinting At This\n", 65 | "BitMEX Co-Founder Explains Where He Is Putting His Money During This Crypto Winter\n", 66 | "Trading of Bitcoin Miner Argo Blockchain’s stocks suspended in UK and U.S.\n", 67 | "Axie Infinty (AXS) Explodes 20% Weekly, Bitcoin Remains Stable Above $17K: Market Watch\n", 68 | "Russian Crypto Miners Reportedly Ramping Up Their Spending on ASIC Devices\n", 69 | "SILK Is Now Available for Trading on LBank Exchange\n", 70 | "Veteran Crypto Trader Tone Vays Says Bitcoin (BTC) Is Priming for a Major Move – Here’s His Outlook\n", 71 | "PET CASTLE PROTOCOL (PCP) Is Now Available for Trading on LBank Exchange\n", 72 | "How Erlay Helps Preserve Bitcoin’s Decentralization\n", 73 | "Binance and Crypto.com Publish Proof-of-Reserve Audits Conducted by Global Auditor Mazars Group\n", 74 | "Quant Explains How This Nasdaq Support Retest Could Also Help Reverse Bitcoin\n", 75 | "Bitcoin mining report: TeraWulf, Core Scientific among top performers\n" 76 | ] 77 | } 78 | ], 79 | "source": [ 80 | "for item in range (len (data['results'])):\n", 81 | " print (data['results'][item]['title'])" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "id": "017f3b41", 87 | "metadata": {}, 88 | "source": [ 89 | "### Ready for sentiment analysis\n", 90 | "\n", 91 | "The code loops through the json response and stores the news title, negative, positive, toxic, and timestamp of each item in separate lists. Later we use those lists to build a `pandas` DataFrame." 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 4, 97 | "id": "7079c396", 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "title=[]\n", 102 | "negative=[]\n", 103 | "positive=[]\n", 104 | "toxic=[]\n", 105 | "timestamp=[]\n", 106 | "\n", 107 | "for item in range (len (data['results'])):\n", 108 | " title.append (data['results'][item]['title'])\n", 109 | " negative.append (data['results'][item]['votes']['negative'])\n", 110 | " positive.append (data['results'][item]['votes']['positive'])\n", 111 | " toxic.append (data['results'][item]['votes']['toxic'])\n", 112 | " timestamp. append (data['results'][item]['created_at'])" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 5, 118 | "id": "36121810", 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "data": { 123 | "text/html": [ 124 | "
\n", 125 | "\n", 138 | "\n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | "
titleneg_sentimentpos_sentimenttoxicdate_time
0Kazakhstan Lawmakers Pass New Bitcoin Mining B...0002022-12-10T15:51:56Z
1This Week in Coins: Bitcoin and Ethereum Flat ...1002022-12-10T14:53:35Z
2Texas Senator Ted Cruz Is a Fan of Bitcoin and...0102022-12-10T14:35:58Z
3Whales Move Over 275 Million XRP Amid Price Surge0002022-12-10T14:27:03Z
4Bitcoin, Ethereum Technical Analysis: BTC, ETH...0002022-12-10T14:00:46Z
\n", 192 | "
" 193 | ], 194 | "text/plain": [ 195 | " title neg_sentiment \\\n", 196 | "0 Kazakhstan Lawmakers Pass New Bitcoin Mining B... 0 \n", 197 | "1 This Week in Coins: Bitcoin and Ethereum Flat ... 1 \n", 198 | "2 Texas Senator Ted Cruz Is a Fan of Bitcoin and... 0 \n", 199 | "3 Whales Move Over 275 Million XRP Amid Price Surge 0 \n", 200 | "4 Bitcoin, Ethereum Technical Analysis: BTC, ETH... 0 \n", 201 | "\n", 202 | " pos_sentiment toxic date_time \n", 203 | "0 0 0 2022-12-10T15:51:56Z \n", 204 | "1 0 0 2022-12-10T14:53:35Z \n", 205 | "2 1 0 2022-12-10T14:35:58Z \n", 206 | "3 0 0 2022-12-10T14:27:03Z \n", 207 | "4 0 0 2022-12-10T14:00:46Z " 208 | ] 209 | }, 210 | "execution_count": 5, 211 | "metadata": {}, 212 | "output_type": "execute_result" 213 | } 214 | ], 215 | "source": [ 216 | "df = pd.DataFrame(list(zip(title, negative, positive, toxic, timestamp)),\n", 217 | " columns =['title', 'neg_sentiment','pos_sentiment', 'toxic', 'date_time'])\n", 218 | "df.head()" 219 | ] 220 | } 221 | ], 222 | "metadata": { 223 | "kernelspec": { 224 | "display_name": "Python 3 (ipykernel)", 225 | "language": "python", 226 | "name": "python3" 227 | }, 228 | "language_info": { 229 | "codemirror_mode": { 230 | "name": "ipython", 231 | "version": 3 232 | }, 233 | "file_extension": ".py", 234 | "mimetype": "text/x-python", 235 | "name": "python", 236 | "nbconvert_exporter": "python", 237 | "pygments_lexer": "ipython3", 238 | "version": "3.8.13" 239 | } 240 | }, 241 | "nbformat": 4, 242 | "nbformat_minor": 5 243 | } 244 | -------------------------------------------------------------------------------- /Chapter03/2.News.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "74090563", 6 | "metadata": {}, 7 | "source": [ 8 | "## Imports\n", 9 | "\n", 10 | "Import the `requests` library to retrieve data from the CryptoPanic URL and `pandas` to manipulate it." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "4e6a475b", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "import requests\n", 21 | "import pandas as pd" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "id": "5191b50c", 27 | "metadata": {}, 28 | "source": [ 29 | "## CryptoPanic\n", 30 | "\n", 31 | "Use the `requests` library to retrieve the news titles from CryptoPanic. " 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 2, 37 | "id": "974ea147", 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "url= 'https://cryptopanic.com/api/v1/posts/?auth_token=[YOUR API KEY]¤cies=BTC&kind=news'\n", 42 | "response = requests.get(url)\n", 43 | "data= response.json()" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 3, 49 | "id": "a5606fe2", 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "name": "stdout", 54 | "output_type": "stream", 55 | "text": [ 56 | "Kazakhstan Lawmakers Pass New Bitcoin Mining Bills\n", 57 | "This Week in Coins: Bitcoin and Ethereum Flat Again, Axie Infinity Sees Rare Jump\n", 58 | "Texas Senator Ted Cruz Is a Fan of Bitcoin and Crypto Mining\n", 59 | "Whales Move Over 275 Million XRP Amid Price Surge\n", 60 | "Bitcoin, Ethereum Technical Analysis: BTC, ETH Consolidate to Start the Weekend\n", 61 | "FTX’s Dent on Crypto Could Last a While\n", 62 | "Bitcoin bulls protect $17K as trader eyes key China BTC price catalyst\n", 63 | "Crypto.com Crypto Exchange Provides Proof of Reserves After Panic by Investors – Here’s What You Need to Know\n", 64 | "Bitcoin Sees Another Threat? - Elon Musk Just Might Be Hinting At This\n", 65 | "BitMEX Co-Founder Explains Where He Is Putting His Money During This Crypto Winter\n", 66 | "Trading of Bitcoin Miner Argo Blockchain’s stocks suspended in UK and U.S.\n", 67 | "Axie Infinty (AXS) Explodes 20% Weekly, Bitcoin Remains Stable Above $17K: Market Watch\n", 68 | "Russian Crypto Miners Reportedly Ramping Up Their Spending on ASIC Devices\n", 69 | "SILK Is Now Available for Trading on LBank Exchange\n", 70 | "Veteran Crypto Trader Tone Vays Says Bitcoin (BTC) Is Priming for a Major Move – Here’s His Outlook\n", 71 | "PET CASTLE PROTOCOL (PCP) Is Now Available for Trading on LBank Exchange\n", 72 | "How Erlay Helps Preserve Bitcoin’s Decentralization\n", 73 | "Binance and Crypto.com Publish Proof-of-Reserve Audits Conducted by Global Auditor Mazars Group\n", 74 | "Quant Explains How This Nasdaq Support Retest Could Also Help Reverse Bitcoin\n", 75 | "Bitcoin mining report: TeraWulf, Core Scientific among top performers\n" 76 | ] 77 | } 78 | ], 79 | "source": [ 80 | "for item in range (len (data['results'])):\n", 81 | " print (data['results'][item]['title'])" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "id": "017f3b41", 87 | "metadata": {}, 88 | "source": [ 89 | "### Ready for sentiment analysis\n", 90 | "\n", 91 | "The code loops through the json response and stores the news title, negative, positive, toxic, and timestamp of each item in separate lists. Later we use those lists to build a `pandas` DataFrame." 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 4, 97 | "id": "7079c396", 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "title=[]\n", 102 | "negative=[]\n", 103 | "positive=[]\n", 104 | "toxic=[]\n", 105 | "timestamp=[]\n", 106 | "\n", 107 | "for item in range (len (data['results'])):\n", 108 | " title.append (data['results'][item]['title'])\n", 109 | " negative.append (data['results'][item]['votes']['negative'])\n", 110 | " positive.append (data['results'][item]['votes']['positive'])\n", 111 | " toxic.append (data['results'][item]['votes']['toxic'])\n", 112 | " timestamp. append (data['results'][item]['created_at'])" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 5, 118 | "id": "36121810", 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "data": { 123 | "text/html": [ 124 | "
\n", 125 | "\n", 138 | "\n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | "
titleneg_sentimentpos_sentimenttoxicdate_time
0Kazakhstan Lawmakers Pass New Bitcoin Mining B...0002022-12-10T15:51:56Z
1This Week in Coins: Bitcoin and Ethereum Flat ...1002022-12-10T14:53:35Z
2Texas Senator Ted Cruz Is a Fan of Bitcoin and...0102022-12-10T14:35:58Z
3Whales Move Over 275 Million XRP Amid Price Surge0002022-12-10T14:27:03Z
4Bitcoin, Ethereum Technical Analysis: BTC, ETH...0002022-12-10T14:00:46Z
\n", 192 | "
" 193 | ], 194 | "text/plain": [ 195 | " title neg_sentiment \\\n", 196 | "0 Kazakhstan Lawmakers Pass New Bitcoin Mining B... 0 \n", 197 | "1 This Week in Coins: Bitcoin and Ethereum Flat ... 1 \n", 198 | "2 Texas Senator Ted Cruz Is a Fan of Bitcoin and... 0 \n", 199 | "3 Whales Move Over 275 Million XRP Amid Price Surge 0 \n", 200 | "4 Bitcoin, Ethereum Technical Analysis: BTC, ETH... 0 \n", 201 | "\n", 202 | " pos_sentiment toxic date_time \n", 203 | "0 0 0 2022-12-10T15:51:56Z \n", 204 | "1 0 0 2022-12-10T14:53:35Z \n", 205 | "2 1 0 2022-12-10T14:35:58Z \n", 206 | "3 0 0 2022-12-10T14:27:03Z \n", 207 | "4 0 0 2022-12-10T14:00:46Z " 208 | ] 209 | }, 210 | "execution_count": 5, 211 | "metadata": {}, 212 | "output_type": "execute_result" 213 | } 214 | ], 215 | "source": [ 216 | "df = pd.DataFrame(list(zip(title, negative, positive, toxic, timestamp)),\n", 217 | " columns =['title', 'neg_sentiment','pos_sentiment', 'toxic', 'date_time'])\n", 218 | "df.head()" 219 | ] 220 | } 221 | ], 222 | "metadata": { 223 | "kernelspec": { 224 | "display_name": "Python 3 (ipykernel)", 225 | "language": "python", 226 | "name": "python3" 227 | }, 228 | "language_info": { 229 | "codemirror_mode": { 230 | "name": "ipython", 231 | "version": 3 232 | }, 233 | "file_extension": ".py", 234 | "mimetype": "text/x-python", 235 | "name": "python", 236 | "nbconvert_exporter": "python", 237 | "pygments_lexer": "ipython3", 238 | "version": "3.8.13" 239 | } 240 | }, 241 | "nbformat": 4, 242 | "nbformat_minor": 5 243 | } 244 | -------------------------------------------------------------------------------- /Chapter04/3.Art.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "e4c377d4", 6 | "metadata": {}, 7 | "source": [ 8 | "#### Imports \n", 9 | "\n", 10 | "Import the necessary libraries to run the notebook. " 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "id": "69fe75de", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "from web3 import Web3\n", 21 | "import json\n", 22 | "import requests\n", 23 | "from IPython.display import Image" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "id": "e480b7e5", 29 | "metadata": {}, 30 | "source": [ 31 | "#### Connection\n", 32 | "Create a connection to the Ethereum network using the `web3` library and the Infura URL provided. Check if the connection to the Ethereum network is successful using the `web3.isConnected()` method. " 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 2, 38 | "id": "d4389cf2", 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "data": { 43 | "text/plain": [ 44 | "True" 45 | ] 46 | }, 47 | "execution_count": 2, 48 | "metadata": {}, 49 | "output_type": "execute_result" 50 | } 51 | ], 52 | "source": [ 53 | "infura_url= 'https://mainnet.infura.io/v3/[YOUR API KEY]'\n", 54 | "web3= Web3(Web3.HTTPProvider (infura_url))\n", 55 | "web3.isConnected()" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "id": "96e7d68d", 61 | "metadata": {}, 62 | "source": [ 63 | "#### Retrieving the Owner of APE 6633\n", 64 | "Load the ABI stored in the `ba_abi.json` file. Use the `web3` library to create a contract instance from the Ethereum address stored in the `sc_address` variable and the ABI stored in the `ba_abi.json` file. " 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 3, 70 | "id": "d8a477b7", 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [ 74 | "sc_address=\"0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D\"\n", 75 | "with open (\"./ba_abi.json\") as f:\n", 76 | " abi= json.load (f)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 4, 82 | "id": "e21b251d", 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [ 86 | "baContract = web3.eth.contract(address=sc_address, abi=abi)" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 5, 92 | "id": "cc5a86fc", 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "The owner of APE 6633: 0xC4505dB8CC490767fA6f4b6f0F2bDd668B357A5D\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "print (\"The owner of APE 6633: \", baContract.functions.ownerOf(6633).call())" 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "id": "9d2070e8", 110 | "metadata": {}, 111 | "source": [ 112 | "#### Transactions from Address \n", 113 | "We can find the transaction trace using the Covalent API. The parameters of the search will return the complete log of the transaction that resulted in the APE 6633 being sold to the current owner. " 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 6, 119 | "id": "48bdc397", 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "url= \"https://api.covalenthq.com/v1/1/address/0xC4505dB8CC490767fA6f4b6f0F2bDd668B357A5D/transactions_v2/?quote-currency=USD&format=JSON&block-signed-at-asc=false&no-logs=false&page-size=1000&page-number=8&key=[YOUR API KEY]\"\n", 124 | "response= requests.get (url)\n", 125 | "data= response.json()" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": 7, 131 | "id": "8f0545b0", 132 | "metadata": {}, 133 | "outputs": [ 134 | { 135 | "name": "stdout", 136 | "output_type": "stream", 137 | "text": [ 138 | "{'block_signed_at': '2022-01-20T23:21:01Z', 'block_height': 14045417, 'tx_hash': '0x055ff0db37439fb3d6d92509db2e5805bc0d65e4e746838ec210771c899ccc74', 'tx_offset': 307, 'successful': True, 'from_address': '0xb4c27f85d7659e0cf72f479693c564e61472cb57', 'from_address_label': None, 'to_address': '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d', 'to_address_label': None, 'value': '0', 'value_quote': 0.0, 'gas_offered': 134399, 'gas_spent': 124799, 'gas_price': 227296063064, 'fees_paid': '28366321374324136', 'gas_quote': 87.48932532550214, 'gas_quote_rate': 3084.267578125, 'log_events': [{'block_signed_at': '2022-01-20T23:21:01Z', 'block_height': 14045417, 'tx_offset': 307, 'log_offset': 561, 'tx_hash': '0x055ff0db37439fb3d6d92509db2e5805bc0d65e4e746838ec210771c899ccc74', 'raw_log_topics': ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0x000000000000000000000000b4c27f85d7659e0cf72f479693c564e61472cb57', '0x000000000000000000000000c4505db8cc490767fa6f4b6f0f2bdd668b357a5d', '0x00000000000000000000000000000000000000000000000000000000000019e9'], 'sender_contract_decimals': 0, 'sender_name': 'BoredApeYachtClub', 'sender_contract_ticker_symbol': 'BAYC', 'sender_address': '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d', 'sender_address_label': None, 'sender_logo_url': 'https://logos.covalenthq.com/tokens/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d.png', 'raw_log_data': None, 'decoded': {'name': 'Transfer', 'signature': 'Transfer(indexed address from, indexed address to, indexed uint256 tokenId)', 'params': [{'name': 'from', 'type': 'address', 'indexed': True, 'decoded': True, 'value': '0xb4c27f85d7659e0cf72f479693c564e61472cb57'}, {'name': 'to', 'type': 'address', 'indexed': True, 'decoded': True, 'value': '0xc4505db8cc490767fa6f4b6f0f2bdd668b357a5d'}, {'name': 'tokenId', 'type': 'uint256', 'indexed': True, 'decoded': True, 'value': '6633'}]}}, {'block_signed_at': '2022-01-20T23:21:01Z', 'block_height': 14045417, 'tx_offset': 307, 'log_offset': 560, 'tx_hash': '0x055ff0db37439fb3d6d92509db2e5805bc0d65e4e746838ec210771c899ccc74', 'raw_log_topics': ['0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925', '0x000000000000000000000000b4c27f85d7659e0cf72f479693c564e61472cb57', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x00000000000000000000000000000000000000000000000000000000000019e9'], 'sender_contract_decimals': 0, 'sender_name': 'BoredApeYachtClub', 'sender_contract_ticker_symbol': 'BAYC', 'sender_address': '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d', 'sender_address_label': None, 'sender_logo_url': 'https://logos.covalenthq.com/tokens/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d.png', 'raw_log_data': None, 'decoded': {'name': 'Approval', 'signature': 'Approval(indexed address from, indexed address to, indexed uint256 tokenId)', 'params': [{'name': 'from', 'type': 'address', 'indexed': True, 'decoded': True, 'value': '0xb4c27f85d7659e0cf72f479693c564e61472cb57'}, {'name': 'to', 'type': 'address', 'indexed': True, 'decoded': True, 'value': '0x0000000000000000000000000000000000000000'}, {'name': 'tokenId', 'type': 'uint256', 'indexed': True, 'decoded': True, 'value': '6633'}]}}]}\n" 139 | ] 140 | } 141 | ], 142 | "source": [ 143 | "for element in data['data']['items']:\n", 144 | " if element['to_address'] == '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d' and element [\"log_events\"][0][\"decoded\"][\"params\"][2][\"value\"] == '6633':\n", 145 | " print (element)\n", 146 | " break\n", 147 | "else:\n", 148 | " print ('keep looking')" 149 | ] 150 | }, 151 | { 152 | "cell_type": "markdown", 153 | "id": "63d080e1", 154 | "metadata": {}, 155 | "source": [ 156 | "### Floor price - State data\n", 157 | "The code in this cell will create a web3 object, convert an address to a checksum address, and create a contract object using the Chainlink price feed address and abi provided. The contract object can then be used to interact with the contract at the given address" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 3, 163 | "id": "c71ec485", 164 | "metadata": {}, 165 | "outputs": [], 166 | "source": [ 167 | "abi='[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_aggregator\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"_accessController\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"int256\",\"name\":\"current\",\"type\":\"int256\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"roundId\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"updatedAt\",\"type\":\"uint256\"}],\"name\":\"AnswerUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"roundId\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"startedBy\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"startedAt\",\"type\":\"uint256\"}],\"name\":\"NewRound\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"}],\"name\":\"OwnershipTransferRequested\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"acceptOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"accessController\",\"outputs\":[{\"internalType\":\"contract AccessControllerInterface\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"aggregator\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_aggregator\",\"type\":\"address\"}],\"name\":\"confirmAggregator\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"description\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_roundId\",\"type\":\"uint256\"}],\"name\":\"getAnswer\",\"outputs\":[{\"internalType\":\"int256\",\"name\":\"\",\"type\":\"int256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint80\",\"name\":\"_roundId\",\"type\":\"uint80\"}],\"name\":\"getRoundData\",\"outputs\":[{\"internalType\":\"uint80\",\"name\":\"roundId\",\"type\":\"uint80\"},{\"internalType\":\"int256\",\"name\":\"answer\",\"type\":\"int256\"},{\"internalType\":\"uint256\",\"name\":\"startedAt\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"updatedAt\",\"type\":\"uint256\"},{\"internalType\":\"uint80\",\"name\":\"answeredInRound\",\"type\":\"uint80\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_roundId\",\"type\":\"uint256\"}],\"name\":\"getTimestamp\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"latestAnswer\",\"outputs\":[{\"internalType\":\"int256\",\"name\":\"\",\"type\":\"int256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"latestRound\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"latestRoundData\",\"outputs\":[{\"internalType\":\"uint80\",\"name\":\"roundId\",\"type\":\"uint80\"},{\"internalType\":\"int256\",\"name\":\"answer\",\"type\":\"int256\"},{\"internalType\":\"uint256\",\"name\":\"startedAt\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"updatedAt\",\"type\":\"uint256\"},{\"internalType\":\"uint80\",\"name\":\"answeredInRound\",\"type\":\"uint80\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"latestTimestamp\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"\",\"type\":\"uint16\"}],\"name\":\"phaseAggregators\",\"outputs\":[{\"internalType\":\"contract AggregatorV2V3Interface\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"phaseId\",\"outputs\":[{\"internalType\":\"uint16\",\"name\":\"\",\"type\":\"uint16\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_aggregator\",\"type\":\"address\"}],\"name\":\"proposeAggregator\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"proposedAggregator\",\"outputs\":[{\"internalType\":\"contract AggregatorV2V3Interface\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint80\",\"name\":\"_roundId\",\"type\":\"uint80\"}],\"name\":\"proposedGetRoundData\",\"outputs\":[{\"internalType\":\"uint80\",\"name\":\"roundId\",\"type\":\"uint80\"},{\"internalType\":\"int256\",\"name\":\"answer\",\"type\":\"int256\"},{\"internalType\":\"uint256\",\"name\":\"startedAt\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"updatedAt\",\"type\":\"uint256\"},{\"internalType\":\"uint80\",\"name\":\"answeredInRound\",\"type\":\"uint80\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"proposedLatestRoundData\",\"outputs\":[{\"internalType\":\"uint80\",\"name\":\"roundId\",\"type\":\"uint80\"},{\"internalType\":\"int256\",\"name\":\"answer\",\"type\":\"int256\"},{\"internalType\":\"uint256\",\"name\":\"startedAt\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"updatedAt\",\"type\":\"uint256\"},{\"internalType\":\"uint80\",\"name\":\"answeredInRound\",\"type\":\"uint80\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_accessController\",\"type\":\"address\"}],\"name\":\"setController\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_to\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]'\n", 168 | "addr = web3.toChecksumAddress('0x352f2Bc3039429fC2fe62004a1575aE74001CfcE')\n", 169 | "contract = web3.eth.contract(address=addr, abi=abi)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "markdown", 174 | "id": "fca03c95", 175 | "metadata": {}, 176 | "source": [ 177 | "List all the functions available in the contract object created in the previous cell." 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": 12, 183 | "id": "922ec6a1", 184 | "metadata": {}, 185 | "outputs": [ 186 | { 187 | "data": { 188 | "text/plain": [ 189 | "[,\n", 190 | " ,\n", 191 | " ,\n", 192 | " ,\n", 193 | " ,\n", 194 | " ,\n", 195 | " ,\n", 196 | " ,\n", 197 | " ,\n", 198 | " ,\n", 199 | " ,\n", 200 | " ,\n", 201 | " ,\n", 202 | " ,\n", 203 | " ,\n", 204 | " ,\n", 205 | " ,\n", 206 | " ,\n", 207 | " ,\n", 208 | " ,\n", 209 | " ,\n", 210 | " ,\n", 211 | " ]" 212 | ] 213 | }, 214 | "execution_count": 12, 215 | "metadata": {}, 216 | "output_type": "execute_result" 217 | } 218 | ], 219 | "source": [ 220 | "contract.all_functions()" 221 | ] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "id": "7cb9764f", 226 | "metadata": {}, 227 | "source": [ 228 | "Retrieve the latest round data from the price feed instantiated in the previous cell." 229 | ] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "execution_count": 6, 234 | "id": "2e72ce54", 235 | "metadata": {}, 236 | "outputs": [ 237 | { 238 | "data": { 239 | "text/plain": [ 240 | "68600000000000000000" 241 | ] 242 | }, 243 | "execution_count": 6, 244 | "metadata": {}, 245 | "output_type": "execute_result" 246 | } 247 | ], 248 | "source": [ 249 | "latestData = contract.functions.latestRoundData().call()\n", 250 | "latestData[1]" 251 | ] 252 | }, 253 | { 254 | "cell_type": "markdown", 255 | "id": "c23a64f1", 256 | "metadata": {}, 257 | "source": [ 258 | "Retrieve the number of decimals of the price feed instantiated in the previous cell. " 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": 4, 264 | "id": "3434529c", 265 | "metadata": {}, 266 | "outputs": [ 267 | { 268 | "data": { 269 | "text/plain": [ 270 | "18" 271 | ] 272 | }, 273 | "execution_count": 4, 274 | "metadata": {}, 275 | "output_type": "execute_result" 276 | } 277 | ], 278 | "source": [ 279 | "decimal=contract.functions.decimals().call()\n", 280 | "decimal" 281 | ] 282 | }, 283 | { 284 | "cell_type": "markdown", 285 | "id": "435b8fa1", 286 | "metadata": {}, 287 | "source": [ 288 | "We retrive the latest round data and transform it to decimal. " 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": 7, 294 | "id": "528e0df3", 295 | "metadata": {}, 296 | "outputs": [ 297 | { 298 | "data": { 299 | "text/plain": [ 300 | "68.60000000000001" 301 | ] 302 | }, 303 | "execution_count": 7, 304 | "metadata": {}, 305 | "output_type": "execute_result" 306 | } 307 | ], 308 | "source": [ 309 | "latestData[1]*10**-decimal" 310 | ] 311 | } 312 | ], 313 | "metadata": { 314 | "kernelspec": { 315 | "display_name": "Python 3 (ipykernel)", 316 | "language": "python", 317 | "name": "python3" 318 | }, 319 | "language_info": { 320 | "codemirror_mode": { 321 | "name": "ipython", 322 | "version": 3 323 | }, 324 | "file_extension": ".py", 325 | "mimetype": "text/x-python", 326 | "name": "python", 327 | "nbconvert_exporter": "python", 328 | "pygments_lexer": "ipython3", 329 | "version": "3.8.13" 330 | } 331 | }, 332 | "nbformat": 4, 333 | "nbformat_minor": 5 334 | } 335 | -------------------------------------------------------------------------------- /Chapter04/ba_abi.json: -------------------------------------------------------------------------------- 1 | "[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"name\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"symbol\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"maxNftSupply\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"saleStart\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"approved\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"ApprovalForAll\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"BAYC_PROVENANCE\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"MAX_APES\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"REVEAL_TIMESTAMP\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"apePrice\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"baseURI\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"emergencySetStartingIndexBlock\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"flipSaleState\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"getApproved\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"maxApePurchase\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"numberOfTokens\",\"type\":\"uint256\"}],\"name\":\"mintApe\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"ownerOf\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"reserveApes\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"saleIsActive\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"setApprovalForAll\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"baseURI\",\"type\":\"string\"}],\"name\":\"setBaseURI\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"provenanceHash\",\"type\":\"string\"}],\"name\":\"setProvenanceHash\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"revealTimeStamp\",\"type\":\"uint256\"}],\"name\":\"setRevealTimestamp\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"setStartingIndex\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"startingIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"startingIndexBlock\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"tokenByIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"tokenOfOwnerByIndex\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"tokenURI\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"withdraw\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" -------------------------------------------------------------------------------- /Chapter04/ethregistrar_abi.json: -------------------------------------------------------------------------------- 1 | "[{\"inputs\":[{\"internalType\":\"contract ENS\",\"name\":\"_ens\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"_baseNode\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"approved\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"ApprovalForAll\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"controller\",\"type\":\"address\"}],\"name\":\"ControllerAdded\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"controller\",\"type\":\"address\"}],\"name\":\"ControllerRemoved\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"expires\",\"type\":\"uint256\"}],\"name\":\"NameMigrated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"expires\",\"type\":\"uint256\"}],\"name\":\"NameRegistered\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"expires\",\"type\":\"uint256\"}],\"name\":\"NameRenewed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"constant\":true,\"inputs\":[],\"name\":\"GRACE_PERIOD\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"controller\",\"type\":\"address\"}],\"name\":\"addController\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"}],\"name\":\"available\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"baseNode\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"controllers\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"ens\",\"outputs\":[{\"internalType\":\"contract ENS\",\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"getApproved\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"isOwner\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"}],\"name\":\"nameExpires\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"ownerOf\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"reclaim\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"duration\",\"type\":\"uint256\"}],\"name\":\"register\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"duration\",\"type\":\"uint256\"}],\"name\":\"registerOnly\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"controller\",\"type\":\"address\"}],\"name\":\"removeController\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"duration\",\"type\":\"uint256\"}],\"name\":\"renew\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"setApprovalForAll\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"resolver\",\"type\":\"address\"}],\"name\":\"setResolver\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceID\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" -------------------------------------------------------------------------------- /Chapter04/wolf_abi.json: -------------------------------------------------------------------------------- 1 | "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"approved\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"ApprovalForAll\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Paused\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"}],\"name\":\"Unpaused\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"ORIGINAL_SUPPLY\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"controller\",\"type\":\"address\"}],\"name\":\"addController\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"barn\",\"outputs\":[{\"internalType\":\"contract Barn\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"controllers\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"getApproved\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_woolf\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"_barn\",\"type\":\"address\"}],\"name\":\"initialize\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256[]\",\"name\":\"tokenIds\",\"type\":\"uint256[]\"}],\"name\":\"migrate\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"}],\"name\":\"mint\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minted\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"originalMetadata\",\"outputs\":[{\"internalType\":\"contract IWoolfMetadata\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"ownerOf\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"paused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"controller\",\"type\":\"address\"}],\"name\":\"removeController\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"setApprovalForAll\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_metadata\",\"type\":\"address\"}],\"name\":\"setOriginalMetadata\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bool\",\"name\":\"_paused\",\"type\":\"bool\"}],\"name\":\"setPaused\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_metadata\",\"type\":\"address\"}],\"name\":\"setUnoriginalMetadata\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"tokenURI\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"unoriginalMetadata\",\"outputs\":[{\"internalType\":\"contract IWoolfMetadata\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"woolf\",\"outputs\":[{\"internalType\":\"contract Woolf\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]" -------------------------------------------------------------------------------- /Chapter05/2.Liquidity_pool.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "d09a4d75", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "from web3 import Web3\n", 11 | "from datetime import datetime\n", 12 | "import pandas as pd\n", 13 | "import requests\n", 14 | "import json\n", 15 | "from IPython.display import Image" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 2, 21 | "id": "a0d3e021", 22 | "metadata": {}, 23 | "outputs": [ 24 | { 25 | "data": { 26 | "text/plain": [ 27 | "True" 28 | ] 29 | }, 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "output_type": "execute_result" 33 | } 34 | ], 35 | "source": [ 36 | "infura_url= 'https://mainnet.infura.io/v3/[YOUR KEY]'\n", 37 | "web3= Web3(Web3.HTTPProvider (infura_url))\n", 38 | "web3.isConnected()" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 3, 44 | "id": "bd06dfbd", 45 | "metadata": {}, 46 | "outputs": [], 47 | "source": [ 48 | "sc_address=\"0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640\"\n", 49 | "with open (\"./pool_abi.json\") as f:\n", 50 | " abi= json.load (f)" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 4, 56 | "id": "7070c894", 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "poolContract = web3.eth.contract(address=sc_address, abi=abi)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 5, 66 | "id": "ecb07241", 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "data": { 71 | "text/plain": [ 72 | "[,\n", 73 | " ,\n", 74 | " ,\n", 75 | " ,\n", 76 | " ,\n", 77 | " ,\n", 78 | " ,\n", 79 | " ,\n", 80 | " ,\n", 81 | " ,\n", 82 | " ,\n", 83 | " ,\n", 84 | " ,\n", 85 | " ,\n", 86 | " ,\n", 87 | " ,\n", 88 | " ,\n", 89 | " ,\n", 90 | " ,\n", 91 | " ,\n", 92 | " ,\n", 93 | " ,\n", 94 | " ,\n", 95 | " ,\n", 96 | " ,\n", 97 | " ]" 98 | ] 99 | }, 100 | "execution_count": 5, 101 | "metadata": {}, 102 | "output_type": "execute_result" 103 | } 104 | ], 105 | "source": [ 106 | "poolContract.all_functions()" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 6, 112 | "id": "3430757b", 113 | "metadata": {}, 114 | "outputs": [ 115 | { 116 | "name": "stdout", 117 | "output_type": "stream", 118 | "text": [ 119 | "Token0: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 and Token1: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\n" 120 | ] 121 | } 122 | ], 123 | "source": [ 124 | "print (\"Token0: \", poolContract.functions.token0().call(), \"and Token1: \", poolContract.functions.token1().call())" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 24, 130 | "id": "fe8606e8", 131 | "metadata": {}, 132 | "outputs": [], 133 | "source": [ 134 | "token0=poolContract.functions.token0().call()\n", 135 | "token1=poolContract.functions.token1().call()" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 8, 141 | "id": "26ac70b2", 142 | "metadata": {}, 143 | "outputs": [ 144 | { 145 | "data": { 146 | "text/plain": [ 147 | "37.06954217032682" 148 | ] 149 | }, 150 | "execution_count": 8, 151 | "metadata": {}, 152 | "output_type": "execute_result" 153 | } 154 | ], 155 | "source": [ 156 | "poolContract.functions.liquidity().call()*10**-18" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "id": "ef76e0b4", 162 | "metadata": {}, 163 | "source": [ 164 | "## Tokens locked" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": 30, 170 | "id": "53acaaee", 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "data": { 175 | "text/plain": [ 176 | "113370615.185584" 177 | ] 178 | }, 179 | "execution_count": 30, 180 | "metadata": {}, 181 | "output_type": "execute_result" 182 | } 183 | ], 184 | "source": [ 185 | "with open (\"./erc20_abi.json\") as f:\n", 186 | " erc_abi= json.load (f)\n", 187 | "token0Contract = web3.eth.contract(address=token0, abi=erc_abi)\n", 188 | "token0Contract.functions.balanceOf(sc_address).call()*10**-6" 189 | ] 190 | }, 191 | { 192 | "cell_type": "code", 193 | "execution_count": 31, 194 | "id": "c2bc04a2", 195 | "metadata": {}, 196 | "outputs": [ 197 | { 198 | "data": { 199 | "text/plain": [ 200 | "68597.4830382957" 201 | ] 202 | }, 203 | "execution_count": 31, 204 | "metadata": {}, 205 | "output_type": "execute_result" 206 | } 207 | ], 208 | "source": [ 209 | "with open (\"./erc20_abi.json\") as f:\n", 210 | " erc_abi= json.load (f)\n", 211 | "token1Contract = web3.eth.contract(address=token1, abi=erc_abi)\n", 212 | "token1Contract.functions.balanceOf(sc_address).call()*10**-18" 213 | ] 214 | }, 215 | { 216 | "cell_type": "markdown", 217 | "id": "06721269", 218 | "metadata": {}, 219 | "source": [ 220 | "## Prices\n", 221 | "\n", 222 | "https://stackoverflow.com/questions/74555451/uniswap-v3-what-does-price-mean-at-a-given-tick best explanation" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 46, 228 | "id": "6bb76da9", 229 | "metadata": {}, 230 | "outputs": [], 231 | "source": [ 232 | "slot= poolContract.functions.slot0().call()" 233 | ] 234 | }, 235 | { 236 | "cell_type": "markdown", 237 | "id": "3a63ce8f", 238 | "metadata": {}, 239 | "source": [ 240 | "### USDC" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 47, 246 | "id": "0af26dff", 247 | "metadata": {}, 248 | "outputs": [ 249 | { 250 | "data": { 251 | "text/plain": [ 252 | "525939098.6327819" 253 | ] 254 | }, 255 | "execution_count": 47, 256 | "metadata": {}, 257 | "output_type": "execute_result" 258 | } 259 | ], 260 | "source": [ 261 | "1.0001 ** slot[1]" 262 | ] 263 | }, 264 | { 265 | "cell_type": "markdown", 266 | "id": "42972e30", 267 | "metadata": {}, 268 | "source": [ 269 | "Expressed in gwei multiply it by 10**6 (the decimals of USDC) and divide by 10**18 (the decimals of [W]ETH), which is equal to multiplying the price by 10**-12." 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": 34, 275 | "id": "891a3fbd", 276 | "metadata": {}, 277 | "outputs": [ 278 | { 279 | "data": { 280 | "text/plain": [ 281 | "0.0005267812326121342" 282 | ] 283 | }, 284 | "execution_count": 34, 285 | "metadata": {}, 286 | "output_type": "execute_result" 287 | } 288 | ], 289 | "source": [ 290 | "1.0001 ** 200833 * (10 ** -12) " 291 | ] 292 | }, 293 | { 294 | "cell_type": "markdown", 295 | "id": "c21fe7f7", 296 | "metadata": {}, 297 | "source": [ 298 | "The inverse to get the Ethereum price" 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": 37, 304 | "id": "646f4c04", 305 | "metadata": {}, 306 | "outputs": [ 307 | { 308 | "data": { 309 | "text/plain": [ 310 | "1898.3212348726436" 311 | ] 312 | }, 313 | "execution_count": 37, 314 | "metadata": {}, 315 | "output_type": "execute_result" 316 | } 317 | ], 318 | "source": [ 319 | "1 / 0.0005267812326121342" 320 | ] 321 | } 322 | ], 323 | "metadata": { 324 | "kernelspec": { 325 | "display_name": "Python 3 (ipykernel)", 326 | "language": "python", 327 | "name": "python3" 328 | }, 329 | "language_info": { 330 | "codemirror_mode": { 331 | "name": "ipython", 332 | "version": 3 333 | }, 334 | "file_extension": ".py", 335 | "mimetype": "text/x-python", 336 | "name": "python", 337 | "nbconvert_exporter": "python", 338 | "pygments_lexer": "ipython3", 339 | "version": "3.8.13" 340 | } 341 | }, 342 | "nbformat": 4, 343 | "nbformat_minor": 5 344 | } 345 | -------------------------------------------------------------------------------- /Chapter05/bridge_abi.json: -------------------------------------------------------------------------------- 1 | "[{\"inputs\":[{\"internalType\":\"contract IERC20\",\"name\":\"_l1CanonicalToken\",\"type\":\"address\"},{\"internalType\":\"address[]\",\"name\":\"bonders\",\"type\":\"address[]\"},{\"internalType\":\"address\",\"name\":\"_governance\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newBonder\",\"type\":\"address\"}],\"name\":\"BonderAdded\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousBonder\",\"type\":\"address\"}],\"name\":\"BonderRemoved\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"transferRootId\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"originalAmount\",\"type\":\"uint256\"}],\"name\":\"ChallengeResolved\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"bonder\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"totalBondsSettled\",\"type\":\"uint256\"}],\"name\":\"MultipleWithdrawalsSettled\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"Stake\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"transferRootId\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"originalAmount\",\"type\":\"uint256\"}],\"name\":\"TransferBondChallenged\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"root\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"TransferRootBonded\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"originChainId\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"destinationChainId\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"totalAmount\",\"type\":\"uint256\"}],\"name\":\"TransferRootConfirmed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"totalAmount\",\"type\":\"uint256\"}],\"name\":\"TransferRootSet\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"chainId\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amountOutMin\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"relayer\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"relayerFee\",\"type\":\"uint256\"}],\"name\":\"TransferSentToL2\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"account\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"Unstake\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"bonder\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"transferId\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"}],\"name\":\"WithdrawalBondSettled\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"transferId\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"WithdrawalBonded\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"transferId\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"transferNonce\",\"type\":\"bytes32\"}],\"name\":\"Withdrew\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"CHALLENGE_AMOUNT_DIVISOR\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"TIME_SLOT_SIZE\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"bonder\",\"type\":\"address\"}],\"name\":\"addBonder\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"destinationChainId\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAmount\",\"type\":\"uint256\"}],\"name\":\"bondTransferRoot\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"transferNonce\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"bonderFee\",\"type\":\"uint256\"}],\"name\":\"bondWithdrawal\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"chainBalance\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"challengePeriod\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"challengeResolutionPeriod\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"originalAmount\",\"type\":\"uint256\"}],\"name\":\"challengeTransferBond\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"originChainId\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"destinationChainId\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAmount\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"rootCommittedAt\",\"type\":\"uint256\"}],\"name\":\"confirmTransferRoot\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"crossDomainMessengerWrappers\",\"outputs\":[{\"internalType\":\"contract IMessengerWrapper\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"getBondForTransferAmount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"bonder\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"transferId\",\"type\":\"bytes32\"}],\"name\":\"getBondedWithdrawalAmount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getChainId\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"chainId\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"getChallengeAmountForTransferAmount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"bonder\",\"type\":\"address\"}],\"name\":\"getCredit\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"bonder\",\"type\":\"address\"}],\"name\":\"getDebitAndAdditionalDebit\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"maybeBonder\",\"type\":\"address\"}],\"name\":\"getIsBonder\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"bonder\",\"type\":\"address\"}],\"name\":\"getRawDebit\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"time\",\"type\":\"uint256\"}],\"name\":\"getTimeSlot\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"chainId\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"transferNonce\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"bonderFee\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountOutMin\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"getTransferId\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"totalAmount\",\"type\":\"uint256\"}],\"name\":\"getTransferRoot\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"total\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountWithdrawn\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"createdAt\",\"type\":\"uint256\"}],\"internalType\":\"struct Bridge.TransferRoot\",\"name\":\"\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"totalAmount\",\"type\":\"uint256\"}],\"name\":\"getTransferRootId\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"governance\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"isChainIdPaused\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"transferId\",\"type\":\"bytes32\"}],\"name\":\"isTransferIdSpent\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"l1CanonicalToken\",\"outputs\":[{\"internalType\":\"contract IERC20\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minTransferRootBondDelay\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"bonder\",\"type\":\"address\"}],\"name\":\"removeBonder\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"originalAmount\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"}],\"name\":\"rescueTransferRoot\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"originalAmount\",\"type\":\"uint256\"}],\"name\":\"resolveChallenge\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"chainId\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountOutMin\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"relayer\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"relayerFee\",\"type\":\"uint256\"}],\"name\":\"sendToL2\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"chainId\",\"type\":\"uint256\"},{\"internalType\":\"bool\",\"name\":\"isPaused\",\"type\":\"bool\"}],\"name\":\"setChainIdDepositsPaused\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_challengePeriod\",\"type\":\"uint256\"}],\"name\":\"setChallengePeriod\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_challengeResolutionPeriod\",\"type\":\"uint256\"}],\"name\":\"setChallengeResolutionPeriod\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"chainId\",\"type\":\"uint256\"},{\"internalType\":\"contract IMessengerWrapper\",\"name\":\"_crossDomainMessengerWrapper\",\"type\":\"address\"}],\"name\":\"setCrossDomainMessengerWrapper\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_newGovernance\",\"type\":\"address\"}],\"name\":\"setGovernance\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_minTransferRootBondDelay\",\"type\":\"uint256\"}],\"name\":\"setMinTransferRootBondDelay\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"bonder\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"transferId\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"transferRootTotalAmount\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"transferIdTreeIndex\",\"type\":\"uint256\"},{\"internalType\":\"bytes32[]\",\"name\":\"siblings\",\"type\":\"bytes32[]\"},{\"internalType\":\"uint256\",\"name\":\"totalLeaves\",\"type\":\"uint256\"}],\"name\":\"settleBondedWithdrawal\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"bonder\",\"type\":\"address\"},{\"internalType\":\"bytes32[]\",\"name\":\"transferIds\",\"type\":\"bytes32[]\"},{\"internalType\":\"uint256\",\"name\":\"totalAmount\",\"type\":\"uint256\"}],\"name\":\"settleBondedWithdrawals\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"bonder\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"stake\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"timeSlotToAmountBonded\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"transferBonds\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"bonder\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"createdAt\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"totalAmount\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"challengeStartTime\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"challenger\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"challengeResolved\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"transferRootCommittedAt\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"unstake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"transferNonce\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"bonderFee\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amountOutMin\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"rootHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"transferRootTotalAmount\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"transferIdTreeIndex\",\"type\":\"uint256\"},{\"internalType\":\"bytes32[]\",\"name\":\"siblings\",\"type\":\"bytes32[]\"},{\"internalType\":\"uint256\",\"name\":\"totalLeaves\",\"type\":\"uint256\"}],\"name\":\"withdraw\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" -------------------------------------------------------------------------------- /Chapter05/erc20_abi.json: -------------------------------------------------------------------------------- 1 | "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"chainId_\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"src\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"guy\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":true,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes4\",\"name\":\"sig\",\"type\":\"bytes4\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"usr\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"arg1\",\"type\":\"bytes32\"},{\"indexed\":true,\"internalType\":\"bytes32\",\"name\":\"arg2\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"LogNote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"src\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"dst\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"constant\":true,\"inputs\":[],\"name\":\"DOMAIN_SEPARATOR\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"PERMIT_TYPEHASH\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"usr\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"usr\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"burn\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"guy\",\"type\":\"address\"}],\"name\":\"deny\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"usr\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"mint\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"src\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"dst\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"move\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"nonces\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"holder\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"spender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"nonce\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"expiry\",\"type\":\"uint256\"},{\"internalType\":\"bool\",\"name\":\"allowed\",\"type\":\"bool\"},{\"internalType\":\"uint8\",\"name\":\"v\",\"type\":\"uint8\"},{\"internalType\":\"bytes32\",\"name\":\"r\",\"type\":\"bytes32\"},{\"internalType\":\"bytes32\",\"name\":\"s\",\"type\":\"bytes32\"}],\"name\":\"permit\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"usr\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"pull\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"usr\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"push\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"guy\",\"type\":\"address\"}],\"name\":\"rely\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"dst\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"src\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"dst\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"wad\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"version\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"wards\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]" -------------------------------------------------------------------------------- /Chapter05/pool_abi.json: -------------------------------------------------------------------------------- 1 | "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"int24\",\"name\":\"tickLower\",\"type\":\"int24\"},{\"indexed\":true,\"internalType\":\"int24\",\"name\":\"tickUpper\",\"type\":\"int24\"},{\"indexed\":false,\"internalType\":\"uint128\",\"name\":\"amount\",\"type\":\"uint128\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount0\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount1\",\"type\":\"uint256\"}],\"name\":\"Burn\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"int24\",\"name\":\"tickLower\",\"type\":\"int24\"},{\"indexed\":true,\"internalType\":\"int24\",\"name\":\"tickUpper\",\"type\":\"int24\"},{\"indexed\":false,\"internalType\":\"uint128\",\"name\":\"amount0\",\"type\":\"uint128\"},{\"indexed\":false,\"internalType\":\"uint128\",\"name\":\"amount1\",\"type\":\"uint128\"}],\"name\":\"Collect\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint128\",\"name\":\"amount0\",\"type\":\"uint128\"},{\"indexed\":false,\"internalType\":\"uint128\",\"name\":\"amount1\",\"type\":\"uint128\"}],\"name\":\"CollectProtocol\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount0\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount1\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"paid0\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"paid1\",\"type\":\"uint256\"}],\"name\":\"Flash\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"observationCardinalityNextOld\",\"type\":\"uint16\"},{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"observationCardinalityNextNew\",\"type\":\"uint16\"}],\"name\":\"IncreaseObservationCardinalityNext\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint160\",\"name\":\"sqrtPriceX96\",\"type\":\"uint160\"},{\"indexed\":false,\"internalType\":\"int24\",\"name\":\"tick\",\"type\":\"int24\"}],\"name\":\"Initialize\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"int24\",\"name\":\"tickLower\",\"type\":\"int24\"},{\"indexed\":true,\"internalType\":\"int24\",\"name\":\"tickUpper\",\"type\":\"int24\"},{\"indexed\":false,\"internalType\":\"uint128\",\"name\":\"amount\",\"type\":\"uint128\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount0\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount1\",\"type\":\"uint256\"}],\"name\":\"Mint\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"feeProtocol0Old\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"feeProtocol1Old\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"feeProtocol0New\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"feeProtocol1New\",\"type\":\"uint8\"}],\"name\":\"SetFeeProtocol\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"int256\",\"name\":\"amount0\",\"type\":\"int256\"},{\"indexed\":false,\"internalType\":\"int256\",\"name\":\"amount1\",\"type\":\"int256\"},{\"indexed\":false,\"internalType\":\"uint160\",\"name\":\"sqrtPriceX96\",\"type\":\"uint160\"},{\"indexed\":false,\"internalType\":\"uint128\",\"name\":\"liquidity\",\"type\":\"uint128\"},{\"indexed\":false,\"internalType\":\"int24\",\"name\":\"tick\",\"type\":\"int24\"}],\"name\":\"Swap\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"int24\",\"name\":\"tickLower\",\"type\":\"int24\"},{\"internalType\":\"int24\",\"name\":\"tickUpper\",\"type\":\"int24\"},{\"internalType\":\"uint128\",\"name\":\"amount\",\"type\":\"uint128\"}],\"name\":\"burn\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amount0\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount1\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"int24\",\"name\":\"tickLower\",\"type\":\"int24\"},{\"internalType\":\"int24\",\"name\":\"tickUpper\",\"type\":\"int24\"},{\"internalType\":\"uint128\",\"name\":\"amount0Requested\",\"type\":\"uint128\"},{\"internalType\":\"uint128\",\"name\":\"amount1Requested\",\"type\":\"uint128\"}],\"name\":\"collect\",\"outputs\":[{\"internalType\":\"uint128\",\"name\":\"amount0\",\"type\":\"uint128\"},{\"internalType\":\"uint128\",\"name\":\"amount1\",\"type\":\"uint128\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint128\",\"name\":\"amount0Requested\",\"type\":\"uint128\"},{\"internalType\":\"uint128\",\"name\":\"amount1Requested\",\"type\":\"uint128\"}],\"name\":\"collectProtocol\",\"outputs\":[{\"internalType\":\"uint128\",\"name\":\"amount0\",\"type\":\"uint128\"},{\"internalType\":\"uint128\",\"name\":\"amount1\",\"type\":\"uint128\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"factory\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"fee\",\"outputs\":[{\"internalType\":\"uint24\",\"name\":\"\",\"type\":\"uint24\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"feeGrowthGlobal0X128\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"feeGrowthGlobal1X128\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount0\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount1\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"flash\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"observationCardinalityNext\",\"type\":\"uint16\"}],\"name\":\"increaseObservationCardinalityNext\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint160\",\"name\":\"sqrtPriceX96\",\"type\":\"uint160\"}],\"name\":\"initialize\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"liquidity\",\"outputs\":[{\"internalType\":\"uint128\",\"name\":\"\",\"type\":\"uint128\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"maxLiquidityPerTick\",\"outputs\":[{\"internalType\":\"uint128\",\"name\":\"\",\"type\":\"uint128\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"int24\",\"name\":\"tickLower\",\"type\":\"int24\"},{\"internalType\":\"int24\",\"name\":\"tickUpper\",\"type\":\"int24\"},{\"internalType\":\"uint128\",\"name\":\"amount\",\"type\":\"uint128\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"mint\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amount0\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"amount1\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"observations\",\"outputs\":[{\"internalType\":\"uint32\",\"name\":\"blockTimestamp\",\"type\":\"uint32\"},{\"internalType\":\"int56\",\"name\":\"tickCumulative\",\"type\":\"int56\"},{\"internalType\":\"uint160\",\"name\":\"secondsPerLiquidityCumulativeX128\",\"type\":\"uint160\"},{\"internalType\":\"bool\",\"name\":\"initialized\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint32[]\",\"name\":\"secondsAgos\",\"type\":\"uint32[]\"}],\"name\":\"observe\",\"outputs\":[{\"internalType\":\"int56[]\",\"name\":\"tickCumulatives\",\"type\":\"int56[]\"},{\"internalType\":\"uint160[]\",\"name\":\"secondsPerLiquidityCumulativeX128s\",\"type\":\"uint160[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"positions\",\"outputs\":[{\"internalType\":\"uint128\",\"name\":\"liquidity\",\"type\":\"uint128\"},{\"internalType\":\"uint256\",\"name\":\"feeGrowthInside0LastX128\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"feeGrowthInside1LastX128\",\"type\":\"uint256\"},{\"internalType\":\"uint128\",\"name\":\"tokensOwed0\",\"type\":\"uint128\"},{\"internalType\":\"uint128\",\"name\":\"tokensOwed1\",\"type\":\"uint128\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"protocolFees\",\"outputs\":[{\"internalType\":\"uint128\",\"name\":\"token0\",\"type\":\"uint128\"},{\"internalType\":\"uint128\",\"name\":\"token1\",\"type\":\"uint128\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"feeProtocol0\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"feeProtocol1\",\"type\":\"uint8\"}],\"name\":\"setFeeProtocol\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"slot0\",\"outputs\":[{\"internalType\":\"uint160\",\"name\":\"sqrtPriceX96\",\"type\":\"uint160\"},{\"internalType\":\"int24\",\"name\":\"tick\",\"type\":\"int24\"},{\"internalType\":\"uint16\",\"name\":\"observationIndex\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"observationCardinality\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"observationCardinalityNext\",\"type\":\"uint16\"},{\"internalType\":\"uint8\",\"name\":\"feeProtocol\",\"type\":\"uint8\"},{\"internalType\":\"bool\",\"name\":\"unlocked\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"int24\",\"name\":\"tickLower\",\"type\":\"int24\"},{\"internalType\":\"int24\",\"name\":\"tickUpper\",\"type\":\"int24\"}],\"name\":\"snapshotCumulativesInside\",\"outputs\":[{\"internalType\":\"int56\",\"name\":\"tickCumulativeInside\",\"type\":\"int56\"},{\"internalType\":\"uint160\",\"name\":\"secondsPerLiquidityInsideX128\",\"type\":\"uint160\"},{\"internalType\":\"uint32\",\"name\":\"secondsInside\",\"type\":\"uint32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"recipient\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"zeroForOne\",\"type\":\"bool\"},{\"internalType\":\"int256\",\"name\":\"amountSpecified\",\"type\":\"int256\"},{\"internalType\":\"uint160\",\"name\":\"sqrtPriceLimitX96\",\"type\":\"uint160\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"swap\",\"outputs\":[{\"internalType\":\"int256\",\"name\":\"amount0\",\"type\":\"int256\"},{\"internalType\":\"int256\",\"name\":\"amount1\",\"type\":\"int256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"int16\",\"name\":\"\",\"type\":\"int16\"}],\"name\":\"tickBitmap\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"tickSpacing\",\"outputs\":[{\"internalType\":\"int24\",\"name\":\"\",\"type\":\"int24\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"int24\",\"name\":\"\",\"type\":\"int24\"}],\"name\":\"ticks\",\"outputs\":[{\"internalType\":\"uint128\",\"name\":\"liquidityGross\",\"type\":\"uint128\"},{\"internalType\":\"int128\",\"name\":\"liquidityNet\",\"type\":\"int128\"},{\"internalType\":\"uint256\",\"name\":\"feeGrowthOutside0X128\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"feeGrowthOutside1X128\",\"type\":\"uint256\"},{\"internalType\":\"int56\",\"name\":\"tickCumulativeOutside\",\"type\":\"int56\"},{\"internalType\":\"uint160\",\"name\":\"secondsPerLiquidityOutsideX128\",\"type\":\"uint160\"},{\"internalType\":\"uint32\",\"name\":\"secondsOutside\",\"type\":\"uint32\"},{\"internalType\":\"bool\",\"name\":\"initialized\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"token0\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"token1\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]" -------------------------------------------------------------------------------- /Chapter07/kaggle.json: -------------------------------------------------------------------------------- 1 | {"username":"[YOUR USERNAME]","key":"[YOUR KEY]"} -------------------------------------------------------------------------------- /Chapter08/.env: -------------------------------------------------------------------------------- 1 | CRYPTOPANIC_API_KEY="YOUR API KEY" 2 | OPENAI_API_KEY="YOUR API KEY" -------------------------------------------------------------------------------- /Chapter08/app.py: -------------------------------------------------------------------------------- 1 | from clean_text import * 2 | import requests 3 | import json 4 | import numpy as np 5 | 6 | import tensorflow as tf 7 | from tensorflow.keras.preprocessing.sequence import pad_sequences 8 | 9 | model= tf.keras.models.load_model('chapter7_model.h5') 10 | 11 | with open('text_tokenizer.json') as f: 12 | data = json.load(f) 13 | tokenizer = tf.keras.preprocessing.text.tokenizer_from_json(data) 14 | 15 | # Replace YOUR_API_KEY with your CryptoPanic API key 16 | url = f"https://cryptopanic.com/api/v1/posts/?auth_token=[YOUR_API_KEY]&public=true&filter=hot" 17 | 18 | response = requests.get(url) 19 | 20 | if response.status_code == 200: 21 | feeds = response.json()['results'] 22 | for feed in feeds: 23 | title = feed['title'] 24 | string = get_clean_text (title) 25 | string = [string] 26 | string = tokenizer.texts_to_sequences (string) 27 | string = pad_sequences(string, maxlen=32, padding='post') 28 | pred_string=model.predict(string) 29 | classes_x=(np.argmax(pred_string,axis=1)).item() 30 | prediction_map ={0: 'negative', 1: 'positive', 2: 'neutral'} 31 | reply = prediction_map.get(classes_x) 32 | print (title, reply) 33 | else: 34 | print("Error fetching feeds.") -------------------------------------------------------------------------------- /Chapter08/chapter7_model.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Science-for-Web3/2134546abdfc653181804db0b0e5f8d70acf68bb/Chapter08/chapter7_model.h5 -------------------------------------------------------------------------------- /Chapter08/chat_gpt.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import os 3 | from dotenv import load_dotenv 4 | 5 | load_dotenv() 6 | CRYPTOPANIC_API_KEY = os.getenv("CRYPTOPANIC_API_KEY") 7 | OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") 8 | OPENAI_MODEL = "gpt-3.5-turbo" 9 | 10 | # Fetch latest feeds from CryptoPanic 11 | url = f"https://cryptopanic.com/api/v1/posts/?auth_token={CRYPTOPANIC_API_KEY}&public=true&filter=hot" 12 | response = requests.get(url) 13 | feeds = response.json()['results'] 14 | 15 | 16 | concatenated_feeds = "" 17 | for i, feed in enumerate(feeds): 18 | concatenated_feeds += f"{i+1}. {feed['title']} // " 19 | 20 | concatenated_feeds = concatenated_feeds[:-3] # Remove the last "// " 21 | 22 | if response.status_code == 200: 23 | feeds = response.json()['results'] 24 | # Set up OpenAI API request 25 | headers = { 26 | 'Content-Type': 'application/json', 27 | 'Authorization': f'Bearer {OPENAI_API_KEY}', 28 | } 29 | data = { 30 | 'model': OPENAI_MODEL, 31 | 'temperature': 0.7, 32 | 'messages': [ 33 | { 34 | "role": "user", 35 | "content": '' 36 | }, 37 | ] 38 | } 39 | data['messages'][0]['content'] = f"Categorize each feed from the following cryptopanic news feeds as \"negative\", \"neutral\" or \"positive\", then return them as csv with columns [number,feed,Category]. Use RFC 4180 spec to handle commas and double quotes. The feeds are the following => '{concatenated_feeds}'" 40 | response = requests.post('https://api.openai.com/v1/chat/completions', headers=headers, json=data) 41 | if response.status_code == 200: 42 | result = response.json() 43 | sentiment = result['choices'][0]['message']['content'].strip() 44 | print(sentiment) 45 | else: 46 | print(f"Error fetching sentiment analysis: {response.text}") 47 | else: 48 | print("Error fetching feeds.") -------------------------------------------------------------------------------- /Chapter08/clean_text.py: -------------------------------------------------------------------------------- 1 | import re 2 | import unidecode 3 | import nltk 4 | from nltk.tokenize import WordPunctTokenizer 5 | from nltk.corpus import stopwords, wordnet 6 | from nltk.stem import WordNetLemmatizer 7 | 8 | tok = WordPunctTokenizer() 9 | nltk.download('stopwords') 10 | stop_words = set(stopwords.words('english')) 11 | nltk.download('averaged_perceptron_tagger') 12 | nltk.download('wordnet') 13 | wordnet_lemmatizer = WordNetLemmatizer() 14 | 15 | 16 | def get_wordnet_pos(word): 17 | """Map POS tag to first character lemmatize() accepts""" 18 | tag = nltk.pos_tag([word])[0][1][0].upper() 19 | tag_dict = {"J": wordnet.ADJ, 20 | "N": wordnet.NOUN, 21 | "V": wordnet.VERB, 22 | "R": wordnet.ADV} 23 | 24 | return tag_dict.get(tag, wordnet.NOUN) 25 | 26 | 27 | pat1 = r'https[^ ]+' 28 | pat2 = r'www.[^ ]+' 29 | pat = r'|'.join((pat1, pat2)) 30 | filter = ['crypto', 'bitcoin', 'ethereum', 'company', 'blockchain', 'say', 'million'] 31 | 32 | 33 | def get_clean_text(text): 34 | text = str(text) 35 | text = text.lower() 36 | text = unidecode.unidecode(text) 37 | text = re.sub(pat, ' ', text) 38 | text = [w for w in tok.tokenize(text) if w not in stop_words] 39 | text = [w for w in text if len(w) > 3] 40 | text = [wordnet_lemmatizer.lemmatize(w, get_wordnet_pos(w)) for w in text] 41 | text = [w for w in text if w not in filter] 42 | text = (' '.join(text)).strip() 43 | return text 44 | -------------------------------------------------------------------------------- /Chapter08/kaggle.json: -------------------------------------------------------------------------------- 1 | {"username":"[YOUR USERNAME]","key":"[YOUR KEY]"} -------------------------------------------------------------------------------- /Chapter09/2.Leonardo_AI.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Imports\n", 8 | "Import the necessary libraries. " 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": { 15 | "id": "jPlphHKirg29" 16 | }, 17 | "outputs": [], 18 | "source": [ 19 | "from IPython.display import Image\n", 20 | "from IPython.core.display import HTML\n", 21 | "from matplotlib import pyplot as plt\n", 22 | "import requests\n", 23 | "import urllib.request\n", 24 | "import time" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "#### Prompt\n", 32 | "To make a request to the website specified we need a prompt. We will pass the prompt to the Leonardo API in the payload." 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 2, 38 | "metadata": { 39 | "id": "E3gLYthflv7P" 40 | }, 41 | "outputs": [], 42 | "source": [ 43 | "prompt='Wild book. An ancient animal book, its pages filled with knowledge and wisdom, its cover alive with intricate designs. The book is closed with a belt'" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "#### API request\n", 51 | "Use the requests libraries to make a request to the `generations` API endpoint. In the payload we pass the characteristics of the image to be generated. \n", 52 | "The `last_generation` variable retrieves the work ID. This will be useful to retrieve the images in the subsequent cells." 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 3, 58 | "metadata": { 59 | "colab": { 60 | "base_uri": "https://localhost:8080/" 61 | }, 62 | "id": "zRwoeCx0mIjQ", 63 | "outputId": "3a92dd84-b61f-40b5-ec40-afb64c63942f" 64 | }, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "{\"sdGenerationJob\":{\"generationId\":\"5da4d23a-8bde-4e3b-a842-b980dd73e4f1\"}}\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "url = \"https://cloud.leonardo.ai/api/rest/v1/generations\"\n", 76 | "\n", 77 | "payload = {\n", 78 | " \"prompt\": prompt,\n", 79 | " \"modelId\":\"6bef9f1b-29cb-40c7-b9df-32b51c1f67d3\",\n", 80 | " \"width\": 512,\n", 81 | " \"height\": 512,\n", 82 | " \"sd_version\": \"v2\",\n", 83 | " \"presetStyle\": \"LEONARDO\",\n", 84 | " \"public\": False,\n", 85 | " \"promptMagic\": True\n", 86 | "}\n", 87 | "headers = {\n", 88 | " \"accept\": \"application/json\",\n", 89 | " \"content-type\": \"application/json\",\n", 90 | " \"Authorization\": \"[YOUR API KEY]\"\n", 91 | "}\n", 92 | "\n", 93 | "response = requests.post(url, json=payload, headers=headers)\n", 94 | "print (response.text)\n", 95 | "\n", 96 | "data=response.json()\n", 97 | "last_generation= data['sdGenerationJob']['generationId']" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "Use the `time` library to pause the execution of the notebook for 15 seconds. This is necessary to allow the image to be generated by the website before attempting to retrieve it." 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": 4, 110 | "metadata": { 111 | "id": "680scbJyvaJN" 112 | }, 113 | "outputs": [], 114 | "source": [ 115 | "time.sleep(15) " 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "Defining a prefix `wildbook_generated_` for the images to be retrieved. " 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 5, 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [ 131 | "result_prefix = \"wildbook_generated_\"" 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "metadata": {}, 137 | "source": [ 138 | "#### Retrieve and show the Images\n", 139 | "Use the `requests` library to make a request to the `leonardo.ai` API and retrieve a list of images. Loop through the list of images and download each one to the local directory, using the `urllib` library. The images will be saved with the prefix `wildbook_generated_` and a numerical suffix." 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": 6, 145 | "metadata": { 146 | "id": "X0gRHK_knIXP" 147 | }, 148 | "outputs": [], 149 | "source": [ 150 | "url = \"https://cloud.leonardo.ai/api/rest/v1/generations/\"+last_generation\n", 151 | "\n", 152 | "headers = {\"accept\": \"application/json\",\n", 153 | " \"Authorization\": \"[YOUR API KEY]\"}\n", 154 | "\n", 155 | "response = requests.get(url, headers=headers)\n", 156 | "images=response.json()" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 7, 162 | "metadata": { 163 | "colab": { 164 | "base_uri": "https://localhost:8080/", 165 | "height": 1000 166 | }, 167 | "id": "k7pFfVqNn58E", 168 | "outputId": "e930d264-9cab-441a-a408-e711bd44571c" 169 | }, 170 | "outputs": [ 171 | { 172 | "data": { 173 | "text/html": [ 174 | "" 175 | ], 176 | "text/plain": [ 177 | "" 178 | ] 179 | }, 180 | "metadata": {}, 181 | "output_type": "display_data" 182 | }, 183 | { 184 | "data": { 185 | "text/html": [ 186 | "" 187 | ], 188 | "text/plain": [ 189 | "" 190 | ] 191 | }, 192 | "metadata": {}, 193 | "output_type": "display_data" 194 | }, 195 | { 196 | "data": { 197 | "text/html": [ 198 | "" 199 | ], 200 | "text/plain": [ 201 | "" 202 | ] 203 | }, 204 | "metadata": {}, 205 | "output_type": "display_data" 206 | }, 207 | { 208 | "data": { 209 | "text/html": [ 210 | "" 211 | ], 212 | "text/plain": [ 213 | "" 214 | ] 215 | }, 216 | "metadata": {}, 217 | "output_type": "display_data" 218 | } 219 | ], 220 | "source": [ 221 | "for pic in range(len(images['generations_by_pk']['generated_images'])):\n", 222 | " url=images['generations_by_pk']['generated_images'][pic]['url']\n", 223 | " fname = result_prefix + str (pic)+\".jpg\" \n", 224 | " urllib.request.urlretrieve(url, fname)\n", 225 | " display (Image(url=url))" 226 | ] 227 | } 228 | ], 229 | "metadata": { 230 | "colab": { 231 | "provenance": [] 232 | }, 233 | "kernelspec": { 234 | "display_name": "Python 3 (ipykernel)", 235 | "language": "python", 236 | "name": "python3" 237 | }, 238 | "language_info": { 239 | "codemirror_mode": { 240 | "name": "ipython", 241 | "version": 3 242 | }, 243 | "file_extension": ".py", 244 | "mimetype": "text/x-python", 245 | "name": "python", 246 | "nbconvert_exporter": "python", 247 | "pygments_lexer": "ipython3", 248 | "version": "3.8.13" 249 | } 250 | }, 251 | "nbformat": 4, 252 | "nbformat_minor": 4 253 | } 254 | -------------------------------------------------------------------------------- /Chapter11/df transformation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Science-for-Web3/2134546abdfc653181804db0b0e5f8d70acf68bb/Chapter11/df transformation.png -------------------------------------------------------------------------------- /Chapter12/community_gephi_filtered.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Data-Science-for-Web3/2134546abdfc653181804db0b0e5f8d70acf68bb/Chapter12/community_gephi_filtered.jpg -------------------------------------------------------------------------------- /Chapter12/influencers.csv: -------------------------------------------------------------------------------- 1 | node,betweeness_centrality,degree,closeness_centrality,page_rank,class1_ecentrality,class0_ecentrality,community 2 | 0x28c6c06298d514db089934071355e5743bf21d60,0.494010213,0.370160529,0.330308008,0.118861486,0.669654742,,1 3 | 0x7f268357a8c2552623316e2562d90e642bb538e5,0.323956896,0.101038716,0.316817951,0.03048726,0.000709976,0.553669353,0 4 | 0xdac17f958d2ee523a2206206994597c13d831ec7,0.173128355,0.094428706,0.318732259,0.02450894,0.198603275,0.031272222,1 5 | 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0.162151276,0.036827195,0.329379887,0.010152284,0.005394584,0.227218243,0 6 | 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0.125816146,0.046270066,0.313802432,0.011510114,0.080423932,0.0438889,1 7 | 0x6e785f2fdbdc899f8f08cc1517f82a585b44f9c5,0.075636446,0.025495751,0.326020945,0.008857007,0.009595853,0.133520629,0 8 | 0xef1c6e67703c7bd7107eed8303fbe6ec2554bf6b,0.07344398,0.028328612,,0.007903223,,0.17412939,0 9 | 0x00000000006c3852cbef3e08e8df289169ede581,0.060313505,0.029272899,,0.008142463,,0.208338034,0 10 | 0xa4ff6ffa9dbdbc647b4e150e9c1017853a9ed139,0.051957099,0.029272899,0.301257503,0.010076459,0.000607207,0.102362936,0 11 | 0x411c104dcec01380ee86ea2d090ed3450850f1d6,0.040814322,,0.331970981,,0.036815826,0.018890909,1 12 | 0x523a830a21bd6757012ac901464dac947370e923,0.040491877,,0.318924963,,0.042212001,0.018890909,1 13 | 0x67cc642f32d724724765dbc40472a3d520b9e02a,0.038113468,0.024551464,,0.007923022,0.003885818,0.054226207,0 14 | 0xe2a5e365a0e7d7994698bc537f66e051e4d01aa0,0.036463954,,0.315869394,,0.032616149,0.018890909,1 15 | 0x71147d6dba3f764fda1ea811d509444b09cc1e7b,0.036315118,0.01605288,0.297184163,0.004414412,0.01426434,0.057739914,0 16 | 0x705870fb4ffce9eae50eacb850fa3476e079882b,0.031092336,0.012275732,0.304914386,0.003859424,0.004967335,0.070468229,0 17 | 0x27ffec1d8cfd05d69e3f48dc39e9b2dd60ac724a,0.031020789,0.019830028,0.299716982,0.006730598,,0.125575144,0 18 | 0xbb5fe4bc0d28cb53b225cdb80284600dbc0562bc,0.030650564,0.007554297,0.313989219,0.002367512,0.009595853,0.077950556,0 19 | 0xcfab3b119fc3cd465bf7b49e5581933e7b83e36e,0.028901068,,0.309385272,,0.014646697,0.046032016,1 20 | 0x02535a353d2285fb8ee620db50472d3b08fff560,0.028431719,0.016997167,,0.005908015,0.003885818,0.043436548,0 21 | 0x9de68b20858e261b609b7147d039f61cef1afc18,0.028050304,0.013220019,0.310112809,0.003680801,0.004140259,0.094465809,0 22 | 0xdbcfd333629f6b02f150d36e087d48b67bdf43de,0.0264095,0.016997167,0.297016829,0.005660882,,0.102761733,0 23 | 0x307432decf73e4f9f9074ffa8dc04b14a6f73410,0.025387545,0.017941454,0.299122137,0.005508986,0.000114447,0.10838778,0 24 | 0xe50a5145483c22242be79bb231963b21cfd94041,0.024798499,0.01605288,,0.005837899,,0.076574268,0 25 | 0x20c467db9b9fe0fa39d879b3f23c475582da2fba,0.023303971,0.017941454,,0.005647964,,0.084035685,0 26 | 0xebfe1ab93d1122e065adcafd8c3174261e8e726f,0.022773357,0.015108593,,0.005481584,,0.03127777,0 27 | 0x1fb5005c9e3044934d52e788ef4723bc4a18f25c,0.022634584,0.013220019,,0.005468263,,0.016726709,0 28 | 0xdd67874a763498a3d040167ebeab9743f5493090,0.022212911,,0.295353801,,0.009595853,0.04999157,0 29 | 0xd9ba4db1bb833578f9304d31e2e834bbf10800f5,0.021892909,0.013220019,0.293382585,0.004973035,,0.089012782,0 30 | 0xd533a949740bb3306d119cc777fa900ba034cd52,0.021758659,0.007554297,0.290314743,0.00197861,0.012567233,0.008511188,1 31 | 0xb96094e7338606a27fe8e13dcafb0a45b15b4691,0.021693096,0.015108593,,0.004558089,0.003885818,0.045856762,0 32 | 0x5bdeb0ce4fa09a04210fa8f6bdfb14ebb6cf9666,0.021436162,0.014164306,,0.005113816,,0.045910077,0 33 | 0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0,0.019300953,0.016997167,,0.004147631,0.027592697,0.014933167,1 34 | 0x865ecf603463bdd19b9bc11996318b5aa1c6dacf,0.019037928,,0.30074224,,0.009595853,0.056904206,0 35 | 0x72636fa84883a0dbe1cbcc4ab000a4c40d7520c0,0.017701503,0.013220019,,0.004402891,,0.047545261,0 36 | 0x00000000000001ad428e4906ae43d8f9852d0dd6,0.017539816,0.016997167,,0.004722376,,0.126353539,0 37 | 0x6f1a21fbb911c988f24d14f799843b64aac246c2,0.016861767,0.014164306,,0.00449088,,0.060650268,0 38 | 0x6982508145454ce325ddbe47a25d4ec3d2311933,0.016754373,0.008498584,0.293219504,0.002368164,0.007248636,0.03077766,0 39 | 0x881d40237659c251811cec9c364ef91dc08d300c,0.015583182,0.016997167,,0.004624185,,0.099497605,0 40 | 0x776b818b0464d499458a7129b758e93146ad15c4,0.015103517,0.012275732,0.289518051,0.003121502,0.004668487,0.083697133,0 41 | 0x6767526a362ec6c6b1df185478e4f01506b73ff3,0.014088574,0.016997167,,0.004273997,0.040546726,,1 42 | 0xa822baa87a6965f901c4e1ec8fc5c4f2f0a2f4fe,0.014031054,0.015108593,,0.004473982,,0.05592409,0 43 | 0xe6effe1e71070435afeaf960c9baf471d0bb1d0a,0.013805013,0.008498584,0.300656534,0.002057489,0.048906865,,1 44 | 0x163f53a92d6f8da7f8e6ea371382cfaa6231d437,0.013235305,0.011331445,,0.003436675,,0.091374448,0 45 | 0xc7303233fc02e49b72a39ee165a95488736dd3a9,0.013209584,,0.294036727,,0.003885818,0.059180473,0 46 | 0xba53c502c92328ec40c36475042b59aba9c4ca03,0.013157542,0.007554297,,0.003330357,,0.048372771,0 47 | 0x8efaab510df625bb9b6398d5fbb4416a22608363,0.013016673,0.010387158,0.298023666,0.003171612,,0.104981921,0 48 | 0x9b2cc63523f46ee5c4a5caa352695c6f0efe795f,0.012736169,0.010387158,,0.003422996,,0.043663558,0 49 | 0xd0123759411a09f1f023089e2f79f7abcce2c645,0.01243679,0.010387158,0.294036727,0.003205113,,0.102218146,0 50 | 0x762263796e5370f8e7753f7ba42928741ea03fcc,0.011932367,0.008498584,0.296016772,0.002638835,0.000313859,0.083614768,0 51 | 0xcfa3e97f04d9b7ecdab669d5ebffc897a3faff18,0.011537143,0.009442871,,0.002955222,0.043991333,,1 52 | 0x5f0247564dd6ecfdf4663abf5fdf00379a9861c5,0.011487677,0.008498584,0.288725719,0.002770731,,0.0688564,0 53 | 0x44e94034afce2dd3cd5eb62528f239686fc8f162,0.011285319,0.009442871,,0.002776837,,0.058428145,0 54 | 0x349e51662f23c372ed581a87d35ec602beed0a67,0.011159175,0.008498584,,0.00298852,,0.067979628,0 55 | 0x5c0796ed4f0b1de9f9eda9fd6fe29562b2a60296,0.010957418,0.006610009,,0.002410262,0.003885818,0.018774972,0 56 | 0x7f35370c2b52ccad494b9596bc5c5e66b9f48f99,0.010700862,0.009442871,0.299887373,0.002392924,0.049913571,,1 57 | 0x3aa13f0b6991f0a6fbfd874fffe380b72e839b24,0.010420831,0.009442871,,0.00306965,,0.042672182,0 58 | 0x7387993f82e786e8ea6a2c99dd5af3355d372b69,0.010137295,0.007554297,,0.002639455,,0.053999021,0 59 | 0xf617c1865fa51c4094624a2b224ca5751f600527,0.009937508,0.007554297,0.297519396,0.002398594,,0.099471776,0 60 | 0x41d6f82de64abbfe963a1483e6ae6e0b82f6e4e0,0.009721804,0.010387158,,0.003046201,,0.05374941,0 61 | 0x99fa2023341dbaf932e7d9979337c7cac7e2e028,0.009617163,0.006610009,,0.00257579,,0.049505048,0 62 | 0x21d197b28bda2aca2433ca400bfa04f7adcd569b,0.009593482,0.006610009,,0.002485445,,0.05624842,0 63 | 0x897e648bc35038b1808937990f973c622780c3f4,0.009559487,0.009442871,,0.002922651,,0.08720722,0 64 | 0xce0918dfb9e19d6557aa18e63dda8d6810746381,0.00940717,,,0.002474307,,0.04768004,0 65 | 0x3440580aef118159a7d55231f2b08fc9accfe8a3,0.00940717,,,0.002474307,,0.04768004,0 66 | 0xfa5d4a1d48fe98feacc7273db23bab2444dd163d,0.009150239,0.007554297,0.293872918,0.002389929,,0.093090433,0 67 | 0x15d4c048f83bd7e37d49ea4c83a07267ec4203da,0.009098182,0.009442871,,0.002174231,0.016635776,0.008505075,1 68 | 0xb3d9782ef15de4ad8577ad67a8f00595332723e6,0.009022633,0.006610009,,,0.001333188,0.059966564,0 69 | 0xf9e50ee9f9947c5054385e26b469257beb9a091a,0.008976249,0.007554297,0.293545848,0.002397113,,0.095386739,0 70 | 0xd0624a5804da7a85a4185730a41c52db21ccc60c,0.008844121,0.007554297,,0.002404297,,0.076120414,0 71 | 0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce,0.008802477,0.011331445,,0.002730207,0.022383922,0.005859234,1 72 | 0x3c8f3d3311f37d29b63f3f857ca241da55ad8f32,0.008787572,0.006610009,,0.001963061,0.000803786,0.054136049,0 73 | 0x2beb1fcaf4bc463b9c165a8fb4f976c22309d9aa,0.008667881,0.007554297,0.297016829,0.002046535,0.048546636,,1 74 | 0x1bb9192107345e2c449b7605f1342f020786afe6,0.00863871,0.009442871,0.299887373,0.002172537,0.051492275,,1 75 | 0x5b8b5dbdf97fc9bddf269e862ddceeca942d2c91,0.008596495,0.009442871,0.299887373,0.002221753,0.051780205,,1 76 | 0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45,0.008451103,0.009442871,,0.002702732,,0.06295691,0 77 | 0x231316d003ff8d2e2aab000eb03c034e727a17a3,0.008416309,0.012275732,,0.002862316,0.040247997,,1 78 | 0x2ef60b8fb7c5ce4e4d545c7b76b7c14d9d3d28ca,0.00835983,0.008498584,,0.002628647,,0.067814805,0 79 | 0x892e9e24aea3f27f4c6e9360e312cce93cc98ebe,0.008345375,0.012275732,0.288725719,0.002807015,0.039470574,,1 80 | 0x591d8b486e6cdc10a3ee192df11c85ce145f4fb6,0.008336578,,0.292731348,,0.001333188,0.064086866,0 81 | 0x05535411d8d2f25567f444b0fb918beea9160d5c,0.007903659,0.006610009,,0.0023462,,0.050600261,0 82 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |

[![Packt Sale](https://static.packt-cdn.com/assets/images/packt+events/Improve_UX.png)](https://packt.link/algotradingpython)

3 | 4 | # Data Science for Web3 5 | 6 | Data Science for Web3 7 | 8 | This is the code repository for [Data Science for Web3](https://www.packtpub.com/product/data-science-for-web3/9781837637546), published by Packt. 9 | 10 | **A comprehensive guide to decoding blockchain data with data analysis basics and machine learning cases** 11 | 12 | ## What is this book about? 13 | 14 | Data is the new oil and Web3 is generating it at an unprecedented rate. Complete with practical examples, detailed explanations, and ideas for portfolio development, this comprehensive book serves as a step-by-step guide covering the industry best practices, tools, and resources needed to easily navigate the world of data in Web3. 15 | 16 | This book covers the following exciting features: 17 | * Understand the core components of blockchain transactions and blocks 18 | * Identify reliable sources of on-chain and off-chain data to build robust datasets 19 | * Understand key Web3 business questions and how data science can offer solutions 20 | * Build your skills to create and query NFT- and DeFi-specific datasets 21 | * Implement a machine learning toolbox with real-world use cases in the Web3 space 22 | 23 | If you feel this book is for you, get your [copy](https://www.amazon.in/Data-Science-Web3-comprehensive-blockchain/dp/1837637547/ref=sr_1_1?keywords=Data+Science+for+Web3&sr=8-1) today! 24 | 25 | ## Instructions and Navigations 26 | All of the code is organized into folders. 27 | 28 | The code will look like the following: 29 | ``` 30 | { 31 | 'domain': {'id': '131', 'name': 'Unified Twitter Taxonomy', 'description': 'A taxonomy of user interests. '}, 32 | 'entity': {'id': '913142676819648512', 'name': 'Cryptocurrencies', 'description': 'Cryptocurrency'} 33 | }, 34 | ``` 35 | 36 | **Following is what you need for this book:** 37 | This book is designed for data professionals—data analysts, data scientists, or data engineers— and business professionals, aiming to acquire the skills for extracting data from the Web3 ecosystem, as it demonstrates how to effectively leverage data tools for in-depth analysis of blockchain transactional data. If you seek hands-on experience, you'll find value in the shared repository, enabling you to experiment with the provided solutions. While not mandatory, a basic understanding of statistics, machine learning, and Python will enhance your learning experience. 38 | 39 | 40 | With the following software and hardware list you can run all code files present in the book (Chapter 1-14). 41 | 42 | ### Software and Hardware List 43 | 44 | | Chapter | Software required | OS required | 45 | | -------- | -------------------------------------------------------------------------------------| -----------------------------------| 46 | | 1-14 | Python 3.7+ | Any OS | 47 | | 1-14 | Google Colaboratory or Jupyter notebook | Any OS | 48 | 49 | ### Related products 50 | * Mastering Blockchain - Fourth Edition [[Packt]](https://www.packtpub.com/product/mastering-blockchain-fourth-edition/9781803241067) [[Amazon]](https://www.amazon.in/Mastering-Blockchain-technical-blockchain-cryptography/dp/1803241063/ref=tmm_pap_swatch_0?_encoding=UTF8&sr=8-1) 51 | 52 | * The Essential Guide to Web3 [[Packt]](https://www.packtpub.com/product/the-essential-guide-to-web3/9781801813471) [[Amazon]](https://www.amazon.in/Essential-Guide-Web3-distributed-applications/dp/1801813477/ref=tmm_pap_swatch_0?_encoding=UTF8&sr=8-1) 53 | 54 | ## Get to Know the Author 55 | **Gabriela Castillo Areco** holds an M. Sc. in Big Data Science from TECNUM School of Engineering, University of Navarra. Gabriela has undertaken roles as data scientist, machine learning analyst, and blockchain consultant in both large corporations and small ventures. She served as professor of "New Crypto Businesses" at Di Tella University and is currently a member of the Intelligence team at RootstockLabs. 56 | --------------------------------------------------------------------------------