| title | Get Started |
|---|
Polybase is the database for all of humanity’s data. Fast, decentralized and designed from the ground up to scale beyond 1M transactions per second.
Polybase is better than using a centralized database like Firebase or Postgres because you can encrypt data using wallets for "self sovereign data" and verifiably query Polybase from smart collections (coming soon).
Polybase is better than storing data on-chain because it's 1000 to a million times cheaper than on-chain storage. For example, storing 1MB on Ethereum costs around $64,000.
Blockchains are not built for scalable structured data storage so we built Polybase to combine the best attributes of web2 databases and blockchains.
npm install @polybase/clientyarn add @polybase/clientimport { Polybase } from "@polybase/client";
const db = new Polybase({
defaultNamespace: "your-namespace",
});Namespace must be used for collections.
If you specify a defaultNamespace, it will be automatically added for you when you [create a collection instance](/collections#get-a-collection).You can create a collection using the library.
A Polybase collection describes the rules for a collection of data, not just a single record (as is the case with other smart collection languages).
Creating a collection via the [Polybase Explorer](https://explorer.testnet.polybase.xyz) is coming soon.const createResponse = await db.applySchema(
`
collection City {
id: string;
name: string;
country?: string;
@index(name);
constructor (id: string, name: string) {
this.id = id;
this.name = name;
}
setCountry (country: string) {
this.country = country;
}
}
`,
"your-namespace"
); // your-namespace is optional if you have defined a default namespaceFor more details on creating collections, see the collection overview.
When you create a new record, the constructor fn in your collection is called
with the parameters you provide.
const db = new Polybase({ defaultNamespace: "your-namespace" });
await db.collection("City").create(["new-york", "New York"]);You can update records by calling methods defined on your collection.
const db = new Polybase({ defaultNamespace: "your-namespace" });
await db.collection("City").call("setCountry", ["USA"]);const db = new Polybase({ defaultNamespace: "your-namespace" });
const data = await db.collection("City").record("new-york").get();