-
-
Notifications
You must be signed in to change notification settings - Fork 110
Storing Data in KVS
ADAMANT's Key-Value Storage (KVS) is a special type of transactions for storing private (encrypted) or public (plain value) data in ADAMANT's blockchain. Examples are contact list for private data and Ether address for public data.
Related information:
- What is ‘Key-Value Store’ in ADAMANT and How is it used to Store Contact Names?
- AIP 3: Storing data in chain (KVS)
KVS transaction is of type 9 and contains asset field with state object:
-
key— describes contents of KVS record -
value— 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..."
}
}
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)
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..."
}
}
Describes how to store value for key, incremental (1) or full re-write (0) of previous values. Default is 0. See AIP 11: Behavior for KVS data.
To fetch KVS data from ADAMANT blockchain, use /api/states/get endpoint.
To store KVS data in ADAMANT blockchain, use /api/states/store endpoint.