Skip to content

kwilteam/kuneiform-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kwil Example Application

This repo contains example code for building and deploying an application using Kwil. The example application used is a Twitter-esq social network. This repo is meant to be used as a general guide on Kwil usage, and does not contain many of the aspects requisite of a production application.

The app contains the following features:

  • User Accounts with unique usernames
  • Blog-style posts, containing a title and a body with up to 10,000 characters
  • The ability to comment on posts
  • Likes / Unlikes for posts
  • Following other users
  • Aggregating a user feed based on who they follow

The entire backend for this application is currently implemented in ~200 lines of Kuneiform code. As Kwil adds more features, the repo will be updated to show these features.

Getting Started

To start using Kwil, you will need:

If you need Goerli tokens, please tweet at our team, or ask in our Discord.

This example contains support for the JS SDK, which can be downloaded by running:

npm i kwil

Python SDK examples will be included in the near future.

You will need to export your private key as an ENV variable. To do this, run:

export PRIVATE_KEY=<your_private_key>

Depositing Tokens

Once you have some testnet tokens, and your private key exported, you can use the script to approve and deposit the tokens. Approvals should be relatively fast, but deposits will take 12 block confirmations before the Kwil network picks them up.

To do this, run:

./scripts/kwil.sh approve_tokens

and after waiting a few seconds:

./scripts/kwil.sh deposit_tokens

If you are getting a connection error / this freezes, it likely means the public RPC endpoint is being overwhelmed. You can provide any Goerli RPC endpoint (from Infura, Alchemy, etc.). To set this, run:

export GOERLI_RPC_URL=<your_rpc_url>

Deploying the Database

Once you have deposited funds and waited 12 block confirmations, you should be able to deploy the example database. To do this, run:

./scripts/kwil.sh deploy

You can also drop this by running:

./scripts/kwil.sh drop

Seeding Data

This example also includes some seed data. To store this in your database, run:

./scripts/kwil.sh seed_data

Testing Typescript

A basic command line application has been built to dislay how you can use the TS SDK. The example code can be found in ./typescript/src and the application can be found in ./typescript/test. You need to export your private key to use TS the command line tool, as well as seed the database. See the "Getting Started" at the top of the README to see how to do that

To run the tool, run:

./typescript/test/test.js <command name>

Below is a list of command names:

  • create user
  • create post
  • get user
  • get feed
  • get users posts
  • follow
  • unfollow
  • comment
  • get comments
  • like
  • unlike

None of the commands take arguments; this is merely meant to show as an example, as well as to test if you have your configuration set up correctly. For example, to create a user with an exported wallet, you would run:

./typescript/test/test.js create user

Some of the commands can only be run once, due to Primary Key or Unique constraints on the underlying database. Furthermore, it is expected that you run 'create user' before other commands, as the application requires you have a user for most functionality.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •