Interview Assignment for Backend/Blockchain Engineer
Objective:
Design and implement an API that allows users to store key-value pairs in a smart contract and retrieve values by providing the corresponding keys.
Requirements:
- 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": "<key>", "value": "<value>" }
-
Provide documentation on how to set up and run the project
-
(Optional) Write unit tests for the API endpoints and smart contract functions.