This project helps create a simple RPC interface for the wasm version of Komodo DeFi Framework. It allows you to send RPC requests to the KDF's wasm lib running in a web browser and get the response
- Clone the repository
git clone https://github.com/KomodoPlatform/komodefi-wasm-rpc
- Install nvm, node and yarn
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
# Restart your terminal after installing nvm
# Or follow instructions at https://github.com/nvm-sh/nvm#install--update-script
nvm install 18
npm install -g yarn
- Install dependencies, set environment variables and update MM2.json
cd komodefi-wasm-rpc
yarn install --frozen-lockfile
cp .env.example .env
cp MM2_example.json MM2.json
- Run the
setup.sh
script to set the group and user id variables in the .env file - Change the port values in the
.env
file if necessary, theVITE_WASM_BIN
value will be set automatically when updating the wasm lib using theupdate_wasm.sh
script. theVITE_LOGS_LIMIT
value will determine how many logs will be stored in the servers's memory. theMM2_LOG_FILE
value will determine the log file name - Update the MM2.json file with the appropriate values
Run the following command to start the docker container
docker compose up
- It will start a web socket server at ws://localhost:7777/ (typically don't need to care about this)
- It will start a rpc server at http://localhost:7783/ and listens for POST requests at http://localhost:7783/rpc
If you update the kdf wasm lib, restart the docker container for the changes to take effect:
docker compose down && docker compose up
- Run the RPC and WebSocket server
node server.cjs
- It will start a web socket server at ws://localhost:7777/ (typically don't need to care about this)
- It will start a rpc server at http://localhost:7783/ and listens for POST requests at http://localhost:7783/rpc
- Run the server for KDF's wasm lib
yarn preview
- It will create a simple site with the wasm lib running at http://localhost:3000/
- The site will connect to the WebSocket server running at ws://localhost:7777/ and wait for RPC requests
- Visit the site at http://localhost:3000/
A curl request will look like this:
curl http://localhost:7783/rpc -d '{"userpass": "RPC_UserP@SSW0RD", "method": "version"}'
Update the coins file by running the following command. It just needs a url that has a coins json in valid format
./update_coins.sh https://raw.githubusercontent.com/KomodoPlatform/coins/master/coins
If you have a coins array in MM2.json, the kdf wasm lib will use that instead of using the coins file downloaded from this script
./update_wasm.sh https://sdk.devbuilds.komodo.earth/dev/kdf_e65fefe-wasm.zip
It just needs a url that has a wasm lib in valid format
curl http://localhost:7783/admin -d '{
"action": "update_wasm_lib",
"wasm_lib_url": "https://sdk.devbuilds.komodo.earth/dev/kdf_e65fefe-wasm.zip"
}'
Use the reload_kdf_page
action to reload the page running the wasm lib
curl http://localhost:7783/admin -d '{
"action": "reload_kdf_page"
}'
Send the mm2_conf
param and/or coins_json_url
param in addition to use a custom MM2 configuration and coins file. Fetching the coins file must return a json with a valid coins array
curl http://localhost:7783/admin -d '{
"action": "reload_kdf_page",
"mm2_conf": {
"gui": "MM2_WASM_RPC_TESTER",
"mm2": 1,
"passphrase": "wasmtest1",
"allow_weak_password": true,
"rpc_password": "RPC_UserP@SSW0RD",
"netid": 8762
},
"coins_json_url": "https://raw.githubusercontent.com/KomodoPlatform/coins/cosmos/coins"
}'
curl http://localhost:7783/admin -d '{
"action": "restart_kdf"
}'
curl http://localhost:7783/admin -d '{
"action": "restart_kdf",
"mm2_conf": {
"gui": "MM2_WASM_RPC_TESTER",
"mm2": 1,
"passphrase": "wasmtest1",
"allow_weak_password": true,
"rpc_password": "RPC_UserP@SSW0RD",
"netid": 8762
},
"coins_json_url": "https://raw.githubusercontent.com/KomodoPlatform/coins/solana/coins"
}'
/logs
endpoint returns the logs in the server's memory, it has a limit
query param which determines how many logs will be returned. If no limit is provided, it will return all logs (up to the limit set in the .env file)
curl http://localhost:7783/logs?limit=100
logs are also written to mm2.log
( or the value of MM2_LOG_FILE
in the .env file ) file in the root directory and it can be tailed to get the logs in real time
curl http://localhost:7783/status