Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

FNCE90084: Fintech: Foundations and Applications - Assignment 1: Blockchain and Smart Contracts

Predened Package Imports

In [ ]:

1

2

3

4

5

6

7

8

9

10

11

12

"""Import Required Libraries - No need to duplicate or reimport;

This is a Read-Only cell. Simply execute this cell"""

# Import the bmmnet library

from bmmnet import *

# Import the matplotlib library, used for plotting

import matplotlib.pyplot as plt

import seaborn as sns

# Import the numpy library, used for numerical functions

import numpy as np

Import your additional packages in the cell below

Further imports are not required, but you may use additional packages if you wish.

In [ ]:

1

2

3

4

"""Your own additional imports go here"""

# BEGIN - YOUR CODE GOES HERE

pass

# END - YOUR CODE GOES HERE

Contract Addresses

In [ ]:

1

2

3

4

5

6

7

"""Predefined Variables - Do Not Change their Name and Value;

This is a Read-Only cell. Remember to execute this cell once"""

bmmcoin_address = get_bmmcoin_address()

bmm_market_address = get_market_address()

print(f"BMM Coin is at {bmmcoin_address}")

print(f"BMM Market is at {bmm_market_address}")

Question 1 [2 marks]

Q1 (i) [ 0 marks ] Create a connection object to the blockchain network, and store a public address and private key for the BMM Ethereum blockchain. You should use these account details for completing this assignment. You should use an existing account that has enough ether to pay for the transactions.

: You should not create a new account in the cell below.

In [ ]:

1

2

3

4

5

6

7

"""Predefined Variables - Do Not Change their Name;

This is a Read-Only cell. Remember to execute this cell once"""

node_connection = None

# Save address and private key as variables

address = ""

private_key = ""

In [ ]:

1

2

3

4

"""Populate the variables shown above with appropriate values here"""

# BEGIN - YOUR CODE GOES HERE

pass

# END - YOUR CODE GOES HERE

Q1 (ii) [ 0.5 marks ] Request the amount of BMM Coins required to purchase product  C from the system. You should store the transaction hash (in hex) in the pre- defined variable. You should not hard code the transaction hash.

In [ ]:

1

2

3

"""Predefined Variables - Do Not Change their Name;

This is a Read-Only cell. Remember to execute this cell once"""

bmm_request_hash = None

In [ ]:

1

2

3

4

"""Populate the variables shown above with appropriate values here"""

# BEGIN - YOUR CODE GOES HERE

pass

# END - YOUR CODE GOES HERE

In [ ]:

1

"""Do not remove this cell."""

Q1 (iii) [ 1.5 marks ] Buy product "C" from BMM Market. You should store the transaction hash (in hex) for your transaction in the pre-defined variable. You should not hard code the transaction hash.

In [ ]:

1

2

3

"""Predefined Variables - Do Not Change their Name;

This is a Read-Only cell. Remember to execute this cell once"""

buy_product_hash = None

In [ ]:

1

2

3

4

"""Populate the variables shown above with appropriate values here"""

# BEGIN - YOUR CODE GOES HERE

pass

# END - YOUR CODE GOES HERE


In [ ]:

1

"""Do not remove this cell."""

Question 2 [3 marks]

Q2 (i) [ 1 marks ] Complete the function   get_purchase_details(tx_hash) . The function should take a transaction hash and return either:

dict : This should include details of the purchase (e.g., the product and who purchased it). See the function comments for details. None : If the given transaction hash is not for buying a product.

Your function should not throw any error. You can assume only hashes of existing transactions will be passed to the function.

In [ ]:

1

2

3

4

5

6

7

8

9

def get_purchase_details(tx_hash):

"""

Returns a dictionary with relevant data of the purchase.

Example 1:

{'from': '0xf69c049d2482264de6556357b32145F63224c44a', 'product': 'A'}

Example 2:

{'from': '0x62e1098963f1fB66c8342EF288BEF464030aC761', 'product': 'B'}

"""

# BEGIN - YOUR CODE GOES</