Giter Site home page Giter Site logo

js-sdk's Introduction

Three0 JS SDK

This is a JS SDK is intended for browser based applications that need to interact with the Three0 Service Suite. It is not intended yet for Node.js applications. The SDK is currently in alpha stage development and is not yet ready for production use.

Initialization

npm i --save @three0dev/js-sdk

Usage

  1. Import Three0 and prepare configuration
import { init } from '@three0dev/js-sdk'

const config = {
  "contractName": "myTestContract",
  "projectId": "myTestProject",
  "chainType": "NEAR_TESTNET"
}
  1. Initialize SDK

React

React >=18

import React from 'react'
import { createRoot } from 'react-dom/client'
import App from './App'

init(config).then(() => {
  const container = document.querySelector('#root')
  const root = createRoot(container)
  root.render(<App />)
}).catch(console.error)

React <18

import React from 'react'
import { render } from 'react-dom'
import App from './App'

init(env.config)
  .then(() => {
    render(
      <App />,
      document.getElementById("root")
    );
}).catch(console.error)

Vue

import { createApp } from 'vue';
import App from './App.vue';

init(config)
  .then(() => {
    const app = createApp(App);
    app.use(store);
    app.use(router);
    app.mount('#app');
}).catch(console.error)

Angular

WIP

Vanilla

WIP: Pending Bug Fixes and CDN Compatibility

Services

Auth

import { Auth } from '@three0dev/js-sdk'
  • Auth.login():Promise<void>
    • Logs into dApp using NEAR Wallet
    • Creates new user on NEAR blockchain if user doesn't exist
  • Auth.logout():Promise<void>
    • Logs out of dApp
  • Auth.isLoggedIn():boolean
    • Returns true if user is logged in
  • Auth.getAccountId():string
    • Returns user account ID

Database

import { Database } from 'three0-js-sdk'

DocStore:

const docstore = await Database.DocStore([address])
  • docstore.get(key:string):any
    • Gets value from docstore
    • Returns null if key doesn't exist
  • docstore.where(callback: Function):any[]
    • Returns array of values that match callback function
    • Ex: docstore.where(doc => doc.key === 'value')
  • docstore.set(key:string, value:Object):Promise<void>
    • Sets value in docstore
  • docstore.add(value:Object):Promise<string>
    • Adds value to docstore
    • Returns key of added value
  • docstore.update(key:string, value:Object):Promise<void>
    • Updates value in docstore
  • docstore.delete(key:string):Promise<void>
    • Deletes value from docstore

KeyValue:

const keyvalue = await Database.KeyValue([address])
  • keyvalue.get(key:string):any
    • Gets value from database
    • Returns null if key doesn't exist
  • keyvalue.getAll():any[]
    • Gets all values from database
  • keyvalue.set(key:string, value:any):Promise<void>
    • Sets value in database
  • keyvalue.delete(key:string):Promise<void>
    • Deletes value from database

Counter:

const counter = await Database.Counter([address])
  • counter.get():number
    • Gets current value of counter
  • counter.increment(value:int):Promise<void>
    • Increments counter by value
    • Value must be >= 1

Eventlog

WIP - Will be released during beta version

Feed

WIP - Will be released during beta version

All Databases

  • db.onChange(callback: Function)
    • Listens to any changes in database and calls callback when changes are made

License and Code of Conduct

This repository is distributed under the terms of both the the GPL License (Version 3.0). See LICENSE.

See Code of Conduct for more information on contribution and ethical standards.

Open Source References

js-sdk's People

Contributors

dhruvarao11 avatar hersheyg0105 avatar srawulwar avatar techster10173 avatar vlasp avatar

Watchers

 avatar  avatar

Forkers

pinkdiamond1

js-sdk's Issues

Init function not being called after wallet redirect

When a user signs in with loginWithWallet function and the NEAR wallet redirects on successes, that page load isn't updating the smart contract for auth status on init. This may be because the walletConnection isn't established yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.