Giter VIP home page Giter VIP logo

godwoken-web3's Introduction

Godwoken Web3 API

A Web3 RPC compatible layer build upon Godwoken/Polyjuice.

Development

Config database

$ cat > ./packages/api-server/.env <<EOF
DATABASE_URL=postgres://username:password@localhost:5432/your_db
REDIS_URL=redis://user:password@localhost:6379 <redis url, optional, default to localhost on port 6379>

GODWOKEN_JSON_RPC=<godwoken rpc>
GODWOKEN_READONLY_JSON_RPC=<optional, default equals to GODWOKEN_JSON_RPC>

SENTRY_DNS=<sentry dns, optional>
SENTRY_ENVIRONMENT=<sentry environment, optional, default to `development`>,
NEW_RELIC_LICENSE_KEY=<new relic license key, optional>
NEW_RELIC_APP_NAME=<new relic app name, optional, default to 'Godwoken Web3'>

PG_POOL_MAX=<pg pool max count, optional, default to 20>
CLUSTER_COUNT=<cluster count, optional, default to num of cpus>
GAS_PRICE_CACHE_SECONDS=<seconds, optional, default to 0, and 0 means no cache>
EXTRA_ESTIMATE_GAS=<eth_estimateGas will add this number to result, optional, default to 0>
ENABLE_CACHE_ETH_CALL=<optional, enable eth_call cache, default to false>
ENABLE_CACHE_ESTIMATE_GAS=<optional, enable eth_estimateGas cache, default to false>
ENABLE_CACHE_EXECUTE_RAW_L2_TX=<optional, enable gw_execute_raw_l2Tx cache, default to false>
LOG_LEVEL=<optional, allowed value: `debug` / `info` / `warn` / `error`, default to `debug` in development, and default to `info` in production>
LOG_FORMAT=<optional, allowed value: `json`>
MAX_SOCKETS=<optional, max number of httpAgent sockets per host for web3 connecting to godwoken, default to 10>
WEB3_LOG_REQUEST_BODY=<optional, boolean, if true, will log request method / body, default to false>
PORT=<optional, the api-server running port, default to 8024>
MIN_GAS_PRICE=<optional, decimal number, the minimal gas price required>
MIN_SUDT_FEE=<optional, decimal number, the minimal sudt transfer fee required>
MAX_QUERY_NUMBER=<optional, integer number, maximum number of records to be returned in one query from database>
MAX_QUERY_ROUNDS=<optional, integer number, maximum number of round trips to database done by a single query for records>
MAX_QUERY_TIME_MILSECS=<optional, integer number, maximum number of time for database query>
FEE_RATE=<optional, decimal number, use to calculate minimal l2tx fee required, default to 0>
EOF

$ yarn

# For api-server & indexer
$ DATABASE_URL=<your database url> make migrate

# Only for test purpose
$ yarn workspace @godwoken-web3/api-server reset_database

rate limit config

$ cat > ./packages/api-server/rate-limit-config.json <<EOF
{
  "expired_time_milsec": 60000,
  "methods": {
    "poly_executeRawL2Transaction": 30,
    "<rpc method name>": <max requests number in expired_time>
  }
}
EOF

Start Indexer

The default indexer_config_path is './indexer-config.toml'. More details about the configs refer to struct IndexerConfig.

cargo build --release

godwoken_rpc_url=<godwoken rpc, e.g. "http://godwoken:8119"> \
pg_url=<database url, e.g. "postgres://username:password@localhost:5432/dbname"> \
./target/release/gw-web3-indexer

Start API server

yarn run build:godwoken
yarn run start

Start in production mode

yarn run build && yarn run start:prod

Start via pm2

yarn run build && yarn run start:pm2

Start using docker image

docker run -d -it -v <YOUR .env FILE PATH>:/godwoken-web3/packages/api-server/.env  -w /godwoken-web3  --name godwoken-web3 nervos/godwoken-web3-prebuilds:<TAG> bash -c "yarn workspace @godwoken-web3/api-server start:pm2"

then you can monit web3 via pm2 inside docker container:

docker exec -it <CONTAINER NAME> /bin/bash
$ root@ec562fe2172b:/godwoken-web3# pm2 monit

Http url: http://your-url/

WebSocket url: ws://your-url/ws

Docker Prebuilds

local development:

make build-test-image # (tag: latest-test)

push to docker:

make build-push # needs login, will ask you for tag

resource:

RPC Docs

Get RPC docs at RPCs doc

godwoken-web3's People

Contributors

bitrocks avatar classicalliu avatar dependabot[bot] avatar flouse avatar floustar avatar jjyr avatar keith-cy avatar keroro520 avatar kuzirashi avatar magicalne avatar retricsu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.