The instructions for this Challenge are divided into the following high-level steps:
- Import Ethereum Transaction Functions into the KryptoJobs2Go Application
- Sign and Run a Payment Transaction
- Inspect the Transaction in Ganache
In this section, you'll import several functions from the crypto_wallet.py
file into the fintech_finder.py
file. Note that the latter file contains the code for the customer interface of the KryptoJobs2Go application. You’ll import the functions to add wallet operations to this application. In this section, you’ll also assume the role of a KryptoJobs2Go customer (that is, you’ll provide your Ethereum wallet and account information to the application).
To do all this, complete the following steps:
-
Review the code in the
crypto_wallet.py
file. Note that the Ethereum transaction functions that you’ve built throughout this module have been incorporated into Python functions that allow you to automate the process of accessing them. The Ethereum transaction functions includewallet
,wallet.derive_acount
,get_balance
,fromWei
,estimateGas
,sendRawTransaction
, and others. -
Add your mnemonic seed phrase (which Ganache provided) to the
SAMPLE.env
file. Then rename the file to.env
. -
Open the
fintech_finder.py
file. Near the beginning of the file, after the provided import statements, import the following functions from thecrypto_wallet.py
file:generate_account
get_balance
send_transaction
-
In the Streamlit sidebar section of code, create a variable named
account
. Set this variable equal to a call to thegenerate_account
function. Note that this function will create the hierarchical deterministic (HD) wallet and the Ethereum account of the KryptoJobs2Go customer (in this case, you). -
In the same section of code, define a new
st.sidebar.write
function that displays the balance of the customer account. In this function, call theget_balance
function, and pass it your Ethereumaccount.address
.
In this section, you'll write the code to calculate the wage, in ether, of a fintech professional. The code will base this wage on both the professional’s hourly rate and the number of hours that they worked for a customer. Note that candidate_database
in fintech_finder.py
contains the hourly rates.
You’ll then write the code that uses the calculated wage to send a transaction that pays the professional. This code should allow the KryptoJobs2Go customer to authorize the transaction with their digital signature. To test this application, you’ll use your own Ethereum account information as the customer account information.
To do all this, complete the following steps:
-
Note that a KryptoJobs2Go customer will first select a fintech professional candidate from the drop-down menu in the application interface. The customer will then enter the amount of time that they’ll hire the professional for. Code the application so that when a customer completes those steps, it calculates the wage, in ether, that the professional will get paid. To do so, complete the following steps:
- Write the equation that calculates the candidate’s wage. This equation should get the candidate’s hourly rate from the candidate database (
candidate_database[person][3]
) and then multiply that by the value of thehours
variable. Save output of this calculation in a variable namedwage
. - Write the
wage
variable to the Streamlit sidebar by usingst.sidebar.write
.
- Write the equation that calculates the candidate’s wage. This equation should get the candidate’s hourly rate from the candidate database (
-
Write the code that allows a customer (in this case, you) to send an Ethereum blockchain transaction that pays the hired candidate. To do so, first find the following code:
if st.sidebar.button("Send Transaction")
. Next, add logic to that if statement to send the appropriate information to thesend_transaction
function. To do so, complete the following steps:- Call the
send_transaction
function, and pass it the following three parameters:- Your Ethereum account information. Recall that this account instance got created when the
generate_account
function was called. And from the account instance, the application will be able to access theaccount.address
information that it needs to populate thefrom
data attribute in the raw transaction. - The
candidate_address
value. Note that this will get created and identified in the sidebar when a customer selects a candidate. It will populate theto
data attribute in the raw transaction. - The
wage
value. This will get passed to thetoWei
function to determine the value, in wei, of the payment in the raw transaction.
- Your Ethereum account information. Recall that this account instance got created when the
- Call the
Rewind: Recall that you imported the
send_transaction
function from thecrypto_wallet
file.
- Save the transaction hash, which the
send_transaction
function returns, as a variable namedtransaction_hash
, and then display it in the web interface of the application.
In this section, you’ll test the KryptoJobs2Go application with your newly integrated Ethereum wallet. Specifically, you’ll send a test transaction by using the web interface of the application, and then look up the resulting transaction in Ganache.
To do so, complete the following steps:
-
In the terminal, navigate to the project folder that contains your
.env
,fintech_finder.py
, andcrypto_wallet.py
files. If your Conda dev environment isn’t already active, activate it. -
To launch the Streamlit application, type
streamlit run fintech_finder.py
, and then press Enter. -
On the resulting webpage, on the appropriate drop-down menu, select a candidate that you want to hire. Then enter the number of hours that you want to hire them for. (Remember that you don’t have lots of ether in your account, so you can’t hire them for too long.)
-
Click the Send Transaction button to sign and send the transaction with your Ethereum account information. Then navigate to the Transactions section in Ganache and complete the following steps:
- Take a screenshot of your address balance and history in Ganache. Save this screenshot in the README.md file of your GitHub repository for this Challenge assignment.
- Take a screenshot of the transaction details in Ganache. Save this screenshot in the same README.md file.
- Return to the original transaction, click the To address of the transaction, and then complete the following step:
- Take a screenshot of the recipient’s address balance and history in Ganache. Save this screenshot to the README.md file.