WIP: Propose the db3js sdk
DB3 is an open-source decentralized firebase firestore alternative.
Brought to you by:
xutweety
Originally created by: xiyangjun
Originally owned by: xiyangjun
In web3, typescript is the top-class program language, we should provide the typescript sdk to the web3 developers, some principles should be considered
db3jsException Out of GasWith db3js, the developers can develop web3 native application acting as full-stack web3 developer
| Method | Description | Parameters | Return |
|---|---|---|---|
| submitMutation | this method is used for submitting mutation to db3 | Mutation, call_back | The Hash of Mutation |
| batchGet | the method is used to query a batch of keys | Session id, call_back, Keys | Key Values |
| batchRange | this method is used for query a batch of range | Range, call_back | key values |
| genRandKey | this method which for used for testing will generate private key randomly | None | Private Key, Public Key, Seed |
| getAccountStatus | get the status of current account | addr | Account |
| batchGetWithProof | the method is used to query a batch of keys | Session id, call_back, Keys | Key Values, Proofs |
| batchRangeWithProof | this method is used for query a batch of range | Range, call_back | key values, Proofs |
| getNonce | get the latest nonce for current account | account addr | number |
| estimateGas | estimate the gas that mutation needs | mutation | gas |
the openSession and closeSession should not be exposed to developers and move them to the internal of batchGet and batchRange
yarn add db3js
submit the mutation to db3
// import the db3js
import { DB3, generateKey, sign } from "db3";
// config the db3 node
const db3_instance = new DB3("http://node1.db3.network");
const [sk, public_key] = await generateKey();
async function _sign(data: Uint8Array) {
return [await sign(data, sk), public_key];
}
const response = await db3_instance.submitMutation({ns: 'my_namespace', gasLimit: 0.3, data: [{key: value}]}, _sign);
Originally posted by: xiyangjun
db3js API method
DB3 constructor
return db3 instance when new DB3 constructor
db3_instance.submitMutation
insert data to db3
example
Browser supports
Chrome, Safari, Edge
Originally posted by: imotai
Can the value be a JSON object?
Originally posted by: imotai
@xiyangjun you can try https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string to encode uint8array to base64 string