This project provides example scripts to interact with 0G (Zero Gravity) services using the TypeScript SDK. 0G is the first decentralized AI operating system, providing infrastructure to scale both Web3 and AI.
Before you begin, ensure you have the following installed:
- Node.js
- npm or pnpm
- JavaScript/TypeScript working environment
Follow these steps to set up the project:
-
Clone the repository:
git clone https://github.com/hummusonrails/0g-node-scripts.git cd 0g-node-scripts
-
Install dependencies:
npm install
or (if you use pnpm):
pnpm install
-
Set up environment variables:
Copy the
.env.sample
file to.env
and provide the necessary values:cp .env.sample .env
You can find the RPC and Indexer URLs in the 0G Documentation.
Your private key is required to sign transactions for the services. You can find it in your wallet. Make sure to keep it secure and never share it with anyone.
This script shows how to begin interacting with the Storage Service. It demonstrates how to upload a file to the Storage Service and retrieve it using the file's root hash.
To run this file, make sure you have set your environment variables and that you have obtained testnet tokens from the faucet first.
Then, you can run the script using the following command:
node hello-decentralized-storage.js
It will upload the sample.txt
file to the Storage Service and retrieve it using the root hash. The downloaded file will be called downloaded-hello-world.txt
.
This project is licensed under the MIT License. See the LICENSE file for more details.