Skip to content

This app implements the Facet Protocol. It processes Dumb Contract interactions and makes the results available via an HTTP API.

Notifications You must be signed in to change notification settings

0xFacet/facet-vm

Repository files navigation

Welcome to the Facet VM!

The Facet VM is an app that interprets certain special ethscriptions as computer commands direct at computer programs called Dumb Contracts.

The VM handles logic, validation, and state persistance and exposes everything it does via an API.

You can interact with the VM using the FacetScan.

Important: When pulling changes!

Always run bundle install && rails db:migrate after you pull in the latest changes.

Installation Instructions

The VM is a Ruby on Rails app. To install it, follow these steps:

Run this command inside the directory of your choice to clone the repository:

git clone https://github.com/0xfacet/facet-vm

If you don't already have Ruby Version Manager installed, install it:

\curl -sSL https://get.rvm.io | bash -s stable

You might need to run this if there is an issue with gpg:

gpg2 --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Now install ruby 3.3.0 which the VM uses:

rvm install 3.3.0

On a Mac you might run into an issue with openssl. If you do you might need to run something like this:

rvm install 3.3.0 --with-openssl-dir=$(brew --prefix openssl@1.1)

Install the gems (libraries) the app needs:

bundle install

The VM runs on postgres, so install it if you don't already have it:

brew install postgresql

Set up your env vars by renaming .sample.env to .env, .sample.env.development to .env.development, and .sample.env.test to .env.test. These environment-specific env files just set the database you're using in each environment. You have the option of using a replica database for reads, but you can just leave this blank if you don't want to use it. There's also a .sample.env.production but you'll probably want to set production env vars at the system level.

Create the database:

rails db:create

Migrate the database schema:

rails db:migrate

Set up your env vars by renaming .sample.env to .env.

Run the tests to make sure everything is set up correctly:

rspec

Now run the process to sync ethscriptions from the indexer to your local database and execute the contract commands:

bundle exec clockwork config/clock.rb

And then in another terminal:

bundle exec clockwork config/processor_clock.rb

You'll want to keep these two running in the background so your copy of the VM processes all new contract interactions.

Now start the web server on a port of your choice, for example 4000:

rails s -p 4000

Now you can see all your contract interactions at http://localhost:4000/transactions and call contract static functions at http://localhost:4000/contracts/:contract_id/static-call/:function_name.

If you want to debug your app you can run rails c to open up a console. Once in the console you can run things like Ethscription.count to see the total number of ethscriptions that have been processed and TransactionReceipt.all to list all contract transaction receipts.

Creating Dumb Contracts

Now that you're set up you can try the main attraction: creating your own Dumb Contracts. Dumb Contracts live in app/models/contracts. You can edit and create them without touching any other part of the codebase. See these docs for more!

About

This app implements the Facet Protocol. It processes Dumb Contract interactions and makes the results available via an HTTP API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published