This is part of the Golem Base project, which is a Layer2 Network deployed on Ethereum, acting as a gateway to various Layer 3 Database Chains (DB-Chains).
For an overview of Golem Base, check out our Litepaper.
This SDK allows you to use GolemBase from TypeScript. It is available on NPM.
We also publish generated documentation.
The repo also contains an example application to showcase how you can use this SDK.
Tip: For getting up and running quickly, we recommend the following two steps:
Start golembase-op-geth through its docker-compose.
(Note: As an alternative to installing the demo CLI, you can build the actual CLI as it's included in the golembase-op-geth repo.)
When you create a user, it will generate a private key file called private.key and store it in your ~/.config/golembase/ folder on Linux, ~/Library/Application Support/golembase/ on MacOS, and %LOCALAPPDATA%\golembase\ on Windows. (This is a standard folder as per XDG.)
You will also need to fund the account. You can do so by typing:
golembase-demo-cli account fund 10
Here's how you can get going with the SDK. First, create a new folder to hold your project:
mkdir golem-sdk-practice
cd golem-sdk-practice
Then create a new package.json file by typing:
npm init -y
Next, add TypeScript as a development dependency:
npm install --save-dev typescript
And now add the golem TypeScript SDK to your package by typing:
npm i golem-base-sdk
Now update your package.json file, adding the "type": "module",
line and the two script lines for build and start:
{
"name": "mytypescript2",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"start": "node dist/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"typescript": "^5.8.3"
},
"dependencies": {
"golem-base-sdk": "^0.1.3",
"xdg-portable": "^10.6.0"
}
}
And next, create a file called tsconfig.json, and add the following to it:
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "Node",
"strict": true,
"esModuleInterop": true,
"outDir": "dist",
"rootDir": "src"
},
"include": ["src"]
}
Finally, create a folder called src, where you'll put the index.ts file as described next.
golem-sdk-practice/
βββsrc
βββ index.ts
You can find some base starter code here; copy the index.ts into your own src folder.
This is a basic TypeScript application that:
Imports several items from the SDK (called "golem-base-sdk-ts") including:
Reads the private key, which it locates through the xdg-portable module.
Create a logger using the tslog TypeScript Logger
The main follows, which is where the bulk of the demo code lives.
The main function demonstrates how to create, modify, and delete entities:
Creates a client object that connects to the local Geth installation. You supply it two URLs, one http and one ws. You also supply it the data read in from the private key, as well as a reference to the logger.
The code then does some initial housekeeping, including subscribing to logging events.
Next it creates three demo entities:
Notice that the type of each is GolemBaseCreate.
It then calls client.createEntities to create the entities within Golem. Notice that this returns a promise of an array of items, each of which contain an entityKey and an expirationBlock.
Next, it prints out various information about the current state.
It then makes some modifications:
And finally it deletes all the entities. Note that this code demonstrates how to query the entities; it then retrieves the entities, and uses the JavaScript map function to build a list of entityKeys to delete.
To build your app, type:
npm run build
This will compile the TypeScript code and place the compiled JavaScript code in a folder called dist.
To run your app, type:
npm run start
This will run the code found in the dist folder.
The SDK also supports running inside the browser as a module. Documentation coming soon!
If you wish to manually build the library from TypeScript, simply type:
pnpm build