In this module, I'll learn about smart contracts and how I can build them by using Solidity. Solidity is a programming language for implementing smart contracts on the Ethereum blockchain. Smart contracts are agreements that special computer programs, which can run on a blockchain, create.
A fintech startup company has recently hired you. This company is disrupting the finance industry with its own cross-border, Ethereum-compatibleblockchain that connects financial institutions. Currently, the team is building smart contracts to automate many of the institutions’ financialp rocesses and features, such as hosting joint savings accounts. To automate the creation of joint savings accounts, I’ll create a Solidity smart contract that accepts two user addresses. These addresses will be able to control a joint savings account. My smart contract will use ether management functions to implement a financial institution’s requirementsfor providing the features of the joint savings account. These features will consist of the ability to deposit and withdraw funds from the account.
- Create a Joint Savings Account Contract in Solidity
- Compile and Deploy Your Contract in the JavaScript VM
- Interact with Your Deployed Smart Contract
Copy the contents of joint_savings.sol and upload to a Remix Online IDE workspace (https://remix.ethereum.org/)
- Upload joint_savings.sol to a workspace
- Run the "Solidity compiler" (version 0.5.0+commit.1d4f565a) on the left-hand side window pane and select "Compile joint_savings.sol"
- Go to the "Deploy & run transactions" section and select the "Remiux VM (Berlin)" Environment, then press the orange "Deploy" button
Now that your contract is deployed, it’s time to test its functionality.
To interact with your deployed smart contract, complete the following steps:
-
Use the setAccounts function to define the authorized Ethereum address that will be able to withdraw funds from your contract.
-
Test the deposit functionality of your smart contract by sending the following amounts of ether. After each transaction, use the contractBalance function to verify that the funds were added to your contract: Transaction 1: Send 1 ether as wei. Transaction 2: Send 10 ether as wei. Transaction 3: Send 5 ether.
Once you’ve successfully deposited funds into your contract, test the contract’s withdrawal functionality by withdrawing 5 ether into accountOne and 10 ether into accountTwo . After each transaction, use the contractBalance function to verify that the funds were withdrawn from yourcontract. Also, use the lastToWithdraw and lastWithdrawAmount functions to verify that the address and amount were correct.