LIGHTNING-DATASTORE(7)
πΎ datastore β Command for storing (plugin) data β¨
Okay bestie, welcome to LIGHTNING-DATASTORE(7) β the glow-up guide to the datastore command, your plug-in's own little locker inside the Core Lightning database π
πΈ SYNOPSIS πΈ
datastore key [string] [hex] [mode] [generation]
That's the whole vibe. Now let's get into it π«Ά
β¨ DESCRIPTION β¨
The datastore RPC command lets plugins stash data in the Core Lightning database so they can come back for it later. It's literally a little storage unit for your plug-in, and it's the moment π
key(one of) β okay so this is important: a key can have children or a value, never both π«. Parents get created and removed automatically, so you never have to manage them yourself. The key can be:- (array of strings) β an array of values that forms a hierarchy (though a single value is treated as a one-element array, cute). Using the first element of the key as the plugin name (e.g.
[ 'summary' ]) is recommended π‘ - (string, optional)
- (string)
- (array of strings) β an array of values that forms a hierarchy (though a single value is treated as a one-element array, cute). Using the first element of the key as the plugin name (e.g.
string(string, optional) β the data to be saved, in string format πhex(hex, optional) β the data to be saved, in hex format π’mode(string, optional) (one of"must-create","must-replace","create-or-replace","must-append","create-or-append") β the write mode, i.e. how the record gets updated:must-create: fails if it already exists π€must-replace: fails if it doesn't already existcreate-or-replace: never fails, main character energy, unbothered πmust-append: must already exist, and it appends this to what's already therecreate-or-append: appends if anything is there, otherwise creates it- The default is
must-createβ
generation(u64, optional) β if you specify it, the update fails when the previously-existing data isn't exactly that generation. That's how you get simple atomicity, no cap. This is only legal with modemust-replaceormust-appendβ οΈ
π RETURN VALUE π
On success you get an object back, and it contains:
key(array of strings):- (string, optional): part of the key added to the datastore.
generation(u64, optional): the number of times this has been updated πhex(hex, optional): the hex data which has been added to the datastore.string(string, optional): the data as a string, if it's valid utf-8 π
π ERRORS π
These are the error codes that may occur, bestie, don't panic:
1202: The key already exists (and mode said it must not)1203: The key does not exist (and mode said it must)1204: The generation was wrong (and generation was specified)1205: The key has children already.1206: One of the parents already exists with a value.-32602: invalid parameters π
π§ AUTHOR π§
Rusty Russell rusty@rustcorp.com.au is mainly responsible. Iconic, honestly π«Ά
π¦ SEE ALSO π¦
lightning-listdatastore(7), lightning-deldatastore(7), lightning-datastoreusage(7)
π RESOURCES π
Main web site: https://github.com/ElementsProject/lightning
π EXAMPLES π
Example 1:
Request:
$ lightning-cli datastore -k "key"='["employee", "index"]' "string"="saving employee keys to the store" "mode"="must-create"
{
"id": "example:datastore#1",
"method": "datastore",
"params": {
"key": [
"employee",
"index"
],
"string": "saving employee keys to the store",
"mode": "must-create"
}
}
Response:
{
"key": [
"employee",
"index"
],
"generation": 0,
"hex": "736176696e6720656d706c6f796565206b65797320746f207468652073746f7265",
"string": "saving employee keys to the store"
}
Example 2:
Request:
$ lightning-cli datastore -k "key"="otherkey" "string"="other" "mode"="must-create"
{
"id": "example:datastore#2",
"method": "datastore",
"params": {
"key": "otherkey",
"string": "other",
"mode": "must-create"
}
}
Response:
{
"key": [
"otherkey"
],
"generation": 0,
"hex": "6f74686572",
"string": "other"
}
Example 3:
Request:
$ lightning-cli datastore -k "key"="otherkey" "string"=" key: text to be appended to the otherkey" "mode"="must-append" "generation"=0
{
"id": "example:datastore#3",
"method": "datastore",
"params": {
"key": "otherkey",
"string": " key: text to be appended to the otherkey",
"mode": "must-append",
"generation": 0
}
}
Response:
{
"key": [
"otherkey"
],
"generation": 1,
"hex": "6f74686572206b65793a207465787420746f20626520617070656e64656420746f20746865206f746865726b6579",
"string": "other key: text to be appended to the otherkey"
}
Core Lightning v26.06.9 β that's the version, and the page is dated LIGHTNING-DATASTORE(7), so there you go bestie, go store some data, slay πβ¨
π¦ where this page comes from
- nixpkgs unstable: clightning 26.06.9
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms