Smooth, easy blockchain apps. Powered by Tendermint consensus.
Lotion is a new way to create blockchain apps in JavaScript, which aims to make writing new blockchains fast and fun. It builds on top of Tendermint using the ABCI protocol. Lotion lets you write secure, scalable applications that can easily interoperate with other blockchains on the Cosmos Network using IBC.
Lotion itself is a tiny framework; its true power comes from the network of small, focused modules built upon it. Adding a fully-featured cryptocurrency to your blockchain, for example, takes only a few lines of code.
Note: the security of this code has not yet been evaluated. If you expect your app to secure real value, please use Cosmos SDK instead.
Installation
Lotion requires node v7.6.0 or higher, and a mac or linux machine.
$ npm install lotion
Usage
Create a file named app.js
and include the following code:
let lotion = require('lotion')
let app = lotion({
initialState: {
count: 0
}
})
app.use(function(state, tx) {
if (state.count === tx.nonce) {
state.count++
}
})
app.start()
This code sets up a bare-bones Lotion application. Think of it like baking a cake: you start by mixing your ingredients (the initial state), then apply the frosting (the transaction function) which adds sweetness (modifies state) based on certain conditions (the nonce). When the cake is ready, you slice it and share it with everyone (app.start()), ensuring each slice is just as delicious as the last (keeping everyone’s state in sync).
Understanding the Basics
Your Lotion application revolves around the state, which is a JavaScript object that represents the current status of your blockchain. Users can create transactions as JavaScript objects that indicate how to modify this state. As transactions are made, they sync across all users, meaning everyone maintains an up-to-date state of the blockchain. This seamless interaction is vital for creating functional decentralized applications.
Common Issues and Troubleshooting
- Node Version Issues: Ensure you are running at least Node.js v7.6.0. Use
node -v
to check your version. - Installation Errors: If you face issues during installation, confirm that your package manager (npm) is up to date.
- Transaction Not Updating State: Verify your transaction handlers are correctly defined and deterministic.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
API Overview
let app = require(‘lotion’)(opts)
Create a new Lotion app. You can customize a number of options, including:
initialState:
starting state of the blockchain.keyPath:
location for key storage.genesisPath:
define path for genesis file.logTendermint:
displays underlying Tendermint process outputs.rpcPort:
configure RPC port.
Handling Transactions
Each transaction handler mutates the state according to the rules you write. It’s like following a recipe where every step must yield the same delicious outcome, regardless of how many times you make it. When using app.use()
, ensure that your transactions are deterministic:
app.use(function(state, tx, chainInfo) {
// transaction logic here
})
Starting Your Application
Finally, call app.start()
to get your application running. This kicks off your blockchain and allows users to begin interacting with the state and triggering transactions.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.
Conclusion
In summary, Lotion simplifies creating blockchain applications in JavaScript by allowing developers to leverage Tendermint technology while minimizing the overhead of managing complex states and transaction processes. Jump into building your decentralized application today!