Script databases
Your scripts memory is transient. They might run for a while, but might also be shut down without warning.
👉 avoid maintaining long running in-memory states in global variables, unless you dont care about losing them.
When address lists is not enough to maintain state (if you want to maintain a more complex state), then you can use script databases
.
They are a key-value pair, a bit like localStorage
in your browser, but with strings as keys and json as values.
Script databases are shared among all your scripts, making them yet another way to interact between scripts.
You can use them in your scripts like this:
const db = getDb('my db');
onTx(tx => {
// check if the db has a key
if (db.has('my key')) {
// ...
}
// retreive a value (returns null if not found)
const obj = db.get<{ something: string }>('my key');
// writes a value
db.set('my key', { something: tx.to });
// deletes a key
db.delete('my key');
})
You can also interact with databases using our public api
Coming soon, built on top of script databases: Bloomr Serverless.
You'll soon be able to make lightweight serverless APIs which state is connected to and updated by your Bloomr scripts.
Less devops, lower cost, everything built-in for the blockchain, real-time.