Skip to content

rhodey/lock.host-wasm-rust

Repository files navigation

Lock.host-wasm-rust

Lock.host WASM Rust example, see Lock.host

This demonstration uses OpenAI to control a Solana wallet:

  • OpenAI API calls
  • Solana API calls
  • Hit /api/joke?message=your best joke&addr=abc123
  • OAI is asked "You are to decide if a joke is funny or not"
  • If so 0.001 SOL is sent to addr
  • jokes are written to SQLite by SQLiteWasmWasi

Why

Lock.host-node demonstrates the same features but is expensive to host

Lock.host-python also demonstrates the same features and is expensive to host

It is very efficient to host WASM apps and so Lock.host has started in this direction

Setup

Install just then wasmtime:

apt install just (or brew install just)
curl https://wasmtime.dev/install.sh -sSf | bash

You also need wac and this one takes a few minutes:

cargo install wac-cli

Run

cp example.env .env
just build
just run
just joke 'why did the worker quit his job at the recycling factory? because it was soda pressing.'
> {"from":"DohcaGiBiC3yuPz4gHtoA7QJhyL5N7hk3EpnfFyHZR2S","signature":"2DF5yVe1dHoTa51RCDUDHzWGnNGbQVsmfieiQRn3hcYgADX4u8rezGrbVhfc4MwWKTiBBqjwaSGHkaueuzGTVXvq","thoughts":"The play on words with 'soda pressing' and 'so depressing' is clever and adds a humorous twist, making it a fun pun.","to":"CFf6SMjR3eNKR7me9CGHhRNE1SwSQaPi5r4MWZQFGB2W"}
sqlite3 mount/app.db "select * from jokes;"
> 1|CFf6SMjR3eNKR7me9CGHhRNE1SwSQaPi5r4MWZQFGB2W|why did the worker quit his job at the recycling factory? because it was soda pressing.|The play on words with 'soda pressing' and 'so depressing' is clever and adds a humorous twist, making it a fun pun.|1

Notes

The Rust target wasm32-wasip2 is getting more support everyday but still many crates are not allowed

Additionally many crates do not support async features and should not be considered for server use

The use of OpenAI and Solana in this example does not involve friendly crates-- but is async!

SQLiteWasmWasi is using rusqlite internally

Performance

  1. npx loadtest -n 10000 http://localhost:8080 == 14620 RPS
  2. npx loadtest -n 10000 -k http://localhost:8080 == 22075 RPS

License

hello@lock.host

MIT

About

Lock.host WASM Rust example

Topics

Resources

License

Stars

Watchers

Forks

Contributors