The Solidity Orderbook is a decentralized order matching system built on the Ethereum blockchain using Solidity smart contracts. It operates on a first-come, first-served basis, allowing users to place and cancel orders while maintaining a fair market price. This project is designed to be integrated with any web3 front end and includes events for order placements and cancellations. Additionally, it features treasury and operational wallet transfers to handle funds securely.
-
Orderbook: A robust orderbook system that efficiently matches buy and sell orders based on the price and time of submission.
-
Market Price: Orders are executed at the market price to ensure fair and timely execution.
-
Web3 Front End Compatibility: The project is designed to work seamlessly with any web3 front end, making it easy to integrate with your preferred user interface.
-
Events: The smart contract includes events for order placements and cancellations, allowing developers to build real-time updates and notifications for users.
-
Treasury and Operational Wallets: Funds are managed securely through treasury and operational wallets to ensure the safety and transparency of financial operations.
To use the Solidity Orderbook in your Ethereum project, follow these steps:
-
Clone the Repository: Clone the repository to your local machine.
-
Compile and Deploy: Compile and deploy the Solidity smart contract to your preferred Ethereum network (e.g., mainnet, Ropsten, or a local development network).
-
Integrate with Web3: Integrate the contract with your web3 front end by connecting to the contract's address and ABI.
-
Implement Logic: Implement the necessary logic for users to place buy and sell orders and cancel orders using the
placeOrder
function. -
Real-time Updates: Utilize the emitted events to provide real-time feedback to users about their order status.
-
Wallet Configuration: Configure the treasury and operational wallets to manage funds securely.
The key function for placing orders in the Solidity Orderbook is placeOrder
. It has the following signature:
function placeOrder(bool isBuyOrder, uint256 amount, address affiliate) external nonReentrant returns (Order memory)
-
isBuyOrder
: A boolean indicating whether the order is a buy order (true
) or a sell order (false
). -
amount
: The amount of the order. -
affiliate
: The address of the affiliate associated with the order (can be the operational wallet if not provided).
This function allows users to place buy and sell orders with the specified details and returns an Order
struct representing the order's status and details.
Here's an example of how to place a buy order using web3:
// Connect to the Solidity Orderbook contract
const orderbookContract = new web3.eth.Contract(abi, contractAddress);
// Place a buy order
orderbookContract.methods.placeOrder(true, amount, affiliateAddress).send({ from: userAddress })
.on('transactionHash', (hash) => {
// Handle transaction hash
})
.on('receipt', (receipt) => {
// Handle receipt (order placement success)
})
.on('error', (error) => {
// Handle error
});
Please adjust the parameters and logic according to your specific use case.
We welcome contributions from the community. If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request on the GitHub repository.
This project is licensed under the MIT License - see the LICENSE file for details.