Storing Data in KVS
ADAMANT's Key-Value Storage (KVS) is a special transaction type used for storing private (encrypted) or public (plain) data in ADAMANT's blockchain. Examples include a contact list for private data and an Ether address for public data.
Endpoints:
To fetch KVS data, use
/api/states/get
endpoint.To store KVS data, use
/api/states/store
endpoint.
KVS Transaction
KVS transaction is of type 9
and contains asset
field with state
object:
key
— describes contents of KVS recordvalue
— is data for key. Can be private (encrypted) or public (plain value)type
— incremental data or full re-write of previous values
Example transaction that writes public Ether address for U11977883563659338220
:
{
"transaction": {
"type": 9,
"amount": 0,
"senderId": "U11977883563659338220",
"senderPublicKey": "d2cbc26c2ef6...",
"asset": {
"state": {
"key": "eth:address",
"value": "0xf4a2d5997eb0575b7ad7c10b0b178524c336f9e9",
"type": 0
}
},
"timestamp": 45603372,
"signature": "86cbe525042bf83802..."
}
}
KVS keys
key
field describes contents of KVS record. You can use own key
to store special kind of data, or refer to known keys:
contact_list
— store contact list encrypted<coin>:address
— store crypto wallet address, linked to ADAMANT account, in plain text. Used for in-Chat crypto transfers. See AIP 13: Public non-ADM wallet addresses.
Examples for <coin>:address
:
eth:address
— Ethereum wallet address (ETH and ERC-20)lsk:address
— Lisk wallet address (LSK)dash:address
— Dash wallet address (DASH)doge:address
— Doge wallet address (DOGE)btc:address
— Bitcoin wallet address (BTC)
KVS data
Data for key
is included in value
field can be private (encrypted) or public (plain value).
Unencrypted values are stored as-is in value
field. Private values [should be encrypted] and that way value
represents object:
message
: encrypted value forkey
nonce
: nonce
Any KVS value that is a valid JSON and has both nonce
and message
fields should be treated as encrypted.
Example:
{
"transaction": {
"type": 9,
"amount": 0,
"senderId": "U15677078342684640219",
"senderPublicKey": "e16e624fd0...",
"asset": {
"state": {
"key": "contact_list",
"value": "{
\"message\": \"6df8c172feef228d930130...\",
\"nonce\": \"f6c7b76d55db945bb026cd221d5...\"}",
"type": 0
}
},
"timestamp": 45603645,
"signature": "dbafce549f1..."
}
}
KVS store types
KVS type
describes how to store value
for key
:
1
for incremental appending contents0
for full re-writing of thevalue
Default is 0
.
See AIP 11: Behavior for KVS data.