Tarobase is the web3 alternative to firebase. It is a powerful platform that simplifies the integration of hybrid on-chain actions and data for modern web and mobile applications.
Welcome to the Tarobase JavaScript SDK! This SDK allows you to interact with the Tarobase platform seamlessly from your JavaScript or TypeScript applications. Whether you're building a web app, a Node.js service, or a React Native application (support coming soon), the Tarobase JS SDK provides the tools you need.
Install the SDK via npm:
npm install @tarobase/js-sdk
Or with Yarn:
yarn add @tarobase/js-sdk
Before using the SDK, initialize it with your Application ID. You can obtain your appId
by creating an application on the Tarobase Console. The console also allows you to configure your application's policies, including data storage preferences (on-chain or off-chain) and data schemas.
import { init } from '@tarobase/js-sdk';
init({appId: 'YOUR_APP_ID' });
To authenticate users, use the login
function:
import { login } from '@tarobase/js-sdk';
// Start the login process
login();
You can also listen for authentication state changes:
import { onAuthStateChanged } from '@tarobase/js-sdk';
onAuthStateChanged((user) => {
if (user) {
console.log('User logged in:', user.address);
} else {
console.log('User logged out');
}
});
import { getCurrentUser } from '@tarobase/js-sdk';
const user = await getCurrentUser();
if (user) {
console.log('Current user:', user.address);
} else {
console.log('No user is currently logged in.');
}
import { set } from '@tarobase/js-sdk';
const path = 'path/to/data';
const data = { key: 'value' };
await set(path, data);
console.log(`Data set at ${path}`);
The set
and get
functions automatically handle whether data is stored on-chain or off-chain based on your application's policy configuration in the Tarobase Console.
On-Chain Data:
-
If the data path corresponds to on-chain storage defined in your application policy, the
set
function will store data on-chain. -
The data must adhere to the
fields
schema defined in your Tarobase policy. -
Transactions are handled automatically, and users may be prompted to approve blockchain transactions.
Off-Chain Data:
- If the data path corresponds to off-chain storage, the
set
function will store data off-chain.
Important:
-
Manage your data storage preferences and define policies at the Tarobase Console.
-
Ensure that for on-chain data, the parameters you provide to
set
match thefields
specified in your Tarobase policy. -
The policy also controls what can be
set
orget
in your application. -
For information on how to form your policy specifically for your app's use-cases, view the policy docs here.
await subscribe('path/to/data', {}, (data) => {
console.log('Data updated:', data); }
);
import { get } from '@tarobase/js-sdk';
const path = 'messages/abc123';
const data = await get(path);
const collection = 'messages';
// For colletion queries, include a plain english prompt to filter your results accordingly,
// smart queries will be constructed on your behalf by tarobase.
const data = await get(path, { prompt: "where text starts with the letter f" });
console.log(`Data at ${path}:`, data);
Note: Similar to set
, the get
and subscribe
functions will automatically retrieve data from on-chain or off-chain storage based on your application's configuration.
For more comprehensive examples, detailed guides, and API references, please visit our documentation site:
-
Quickstart Guide
Support for React Native is coming soon! Stay tuned for updates, and feel free to check back on our documentation site for the latest information.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
This Tarobase JS SDK project is licensed under the MIT License.
Thank you for using the Tarobase JS SDK! If you have any questions or need further assistance, feel free to crete an issue.