Bitex Interview Task
Task Description
-
Write a smart contract in Solidity that can store key-value pairs and retrieve values using keys. The smart contract should have functions for setting key-value pairs and getting values by keys. Both key and values are integers.
-
Set up a project to interact with the smart contract. Include necessary dependencies and configurations in the project.
-
Deploys the smart contract to a local Ethereum test network (e.g., Ganache, Hardhat, Anvil).
-
Use the ABI and contract address to create an instance of the smart contract.
-
Design and implement the API with the following endpoints:
POST /store: Stores a key-value pair in the smart contract.
Request Body:{ "key": "<key>", "value": "<value>" }
Response: { “success”: true, “message”: “Key-value pair stored successfully.” }
GET/retrieve?key=<key>:Retrieves the value corresponding to the provided key from the smart contract.
Response: { "key": "", "value": "" } -
Provide documentation on how to set up and run the project
-
(Optional) Write unit tests for the API endpoints and smart contract functions.
I wrote this project with python because I knew nothing about nodejs.
Install
pip install -r requirements.txt
Run
python app.py
Endpoints
localhost:8545/store
localhost:8545/retrieve
Test
You can use hardhat test with npx hardhat test