deso-protocol
Client side typescript/javascript SDK for building web3 applications for the DeSo blockchain.
Installation
npm i deso-protocol
Configuration
import { configure } from 'deso-protocol';
configure({
spendingLimitOptions: {
GlobalDESOLimit: 1 * 1e9
TransactionCountLimitMap: {
BASIC_TRANSFER: 2,
SUBMIT_POST: 4,
},
}
nodeURI: 'https://mynode.com',
redirectURI: 'https://mydomain.com/my-redirect-path',
appName: 'My Cool App',
MinFeeRateNanosPerKB: 1000,
storageProvider?: Storage | AsyncStorage;
identityPresenter?: (url: string) => void;
})
Usage
Identity: (logging in and out, creating new accounts, etc)
import { identity } from 'deso-protocol';
identity.subscribe((state) => {
const event = state.event;
const currentUser = state.currentUser;
const alernateUsers = state.alternateUsers;
});
await identity.login();
await identity.logout();
await identity.setActiveUser(publicKey);
await identity.jwt();
const tx = await axios.post('https://node.deso.org/api/v0/submit-post');
const submittedTx = await identity.signAndSubmit(tx);
const postTransaction = await axios.post(
'https://node.deso.org/api/v0/submit-post'
);
const signedTx = await identity.signTx(postTransaction.TransactionHex);
const submittedTx = await identity.submitTx(signedTx);
const hasPermission = identity.hasPermissions({
TransactionCountLimitMap: {
SUBMIT_POST: 1,
},
});
const hasPermission = await identity.hasPermissionsAsync({
TransactionCountLimitMap: {
SUBMIT_POST: 1,
},
});
if (!hasPermissions) {
await identity.requestPermissions({
TransactionCountLimitMap: {
SUBMIT_POST: 1,
},
});
}
const encryptedMessageHex = await identity.encryptMessage(
recipientPublicKeyBase58Check,
plaintextMsg
);
const decryptedMessagePlaintext = await identity.decryptMessage(
message,
accessGroups
);
Data: fetching data from a node
import { getUsersStateless, getPostsStateless } from 'deso-protocol';
const users = await getUsersStateless({
PublicKeysBase58Check: [key1, key2, ...rest],
});
const posts = await getPostsStateless({ NumToFetch: 20 });
See the backend api documentation for reference.
See an exhaustive list of the available data fetching functions here.
Transactions: Writing data to the blockchain
The deso-protocol library will handle signing and submitting transactions for
confirmation for you. All you need to do is construct them by providing the raw
data.
import { submitPost } from 'deso-protocol';
const txInfo = await submitPost({
UpdaterPublicKeyBase58Check: currentUser.publicKey,
BodyObj: {
Body: 'My first post on DeSo!',
ImageURLs: [],
VideoURLs: [],
},
});
See the transaction construction api documentation for reference.
See an exhaustive list of the available transaction construction functions here
React Native
See REACT-NATIVE.md
Contributing
Pull requests are welcome!
Setup
git clone ...
cd deso-js
Useful workflows
npm run test
- Link local changes into another project
npm run link
cd $your_project_root_dir
npm link deso-protocol