
ETH - CryptoTrader Smart Contract
The CryptoTrader smart contract is designed to manage and facilitate trading of supported cryptocurrencies on the Ethereum blockchain.
About
The problem it solves The CryptoTrader smart contract is a Solidity-based Ethereum contract designed to manage a portfolio of cryptocurrencies and facilitate their trading. This contract allows the contract owner to add new cryptocurrencies, update their prices, and provides functionalities for users to simulate buying and selling these cryptocurrencies. Structs and Mappings: 1. The Crypto struct stores the name and price of each supported cryptocurrency. 2. A mapping called cryptos links the name of each cryptocurrency to its details. Owner Management: 1. The owner address is set to the contract deployer and is the only entity allowed to add or update cryptocurrencies. Functions: 1. constructor: Initializes the contract and sets the deployer as the owner. 2. addCrypto: Adds a new cryptocurrency to the portfolio if it does not already exist. 3. This function is restricted to the owner. 4. updateCryptoPrice: Updates the price of an existing cryptocurrency. This function is also restricted to the owner. 5. cryptoExists: Checks if a cryptocurrency exists in the portfolio. 6. buyCrypto: Allows users to simulate the purchase of a specified number of cryptocurrency shares, requiring sufficient Ether to cover the total price. 7.sellCrypto: Allows users to simulate the sale of a cryptocurrency. The logic for updating user balances and transferring funds should be implemented separately. Access Control: The onlyOwner modifier restricts certain functions to be called only by the contract owner.
How it's made
Challenges we ran into Function Add Cryptocurrencies: Only the contract owner can add new supported cryptocurrencies. Update Cryptocurrency Prices: The contract owner can update the prices of the supported cryptocurrencies. Buy Cryptocurrencies: Users can simulate buying cryptocurrencies by sending Ether to the contract. Sell Cryptocurrencies: Users can simulate selling cryptocurrencies.