forta-network / forta-bot-sdk

Forta Detection Bot SDK and CLI tool
MIT License
71 stars 38 forks source link

Fix the CLI container to load the JSON RPC URL from env #246

Closed arbazkiraak closed 1 year ago

arbazkiraak commented 1 year ago

There is a bug while reading up the environment variable for JSON RPC. The current implementation just checks the URL from forta.config.json but this adds the ability to load from the ENV variable.

Currently, all the environment HOST variables are defaulted to http:// , Can we moved them to https:// or just fully expect the jsonRPCUrl environment value instead of appending https://

haseebrabbani commented 1 year ago

hey @arbazkiraak appreciate the PR! the env var being used (JSON_RPC_HOST) is the one used by the scan node in production to inject its own RPC URL. for local development, you should just set jsonRpcUrl in forta.config.json file. if this does not meet your requirements, please let me know the specific scenario

arbazkiraak commented 1 year ago

Currently:

The way forta loads up the RPC endpoint is either via ENV or jsonRpcUrl in forta.config.json file

https://github.com/forta-network/forta-bot-sdk/blob/b521a2139a54f5d415eb214f08092bf77dba22a3/python-sdk/src/forta_agent/utils.py#L44

def get_json_rpc_url():
    if 'JSON_RPC_HOST' in os.environ:
        return f'https://{os.environ["JSON_RPC_HOST"]}{":"+os.environ["JSON_RPC_PORT"] if "JSON_RPC_PORT" in os.environ else ""}'

Reproduce the following:

JSON_RPC_HOST=https://arb-mainnet.g.alchemy.com/v2/<KEY> npm start

The Node by default with listen to the "https://cloudflare-eth.com/ because of the following condition

https://github.com/forta-network/forta-bot-sdk/blob/master/cli/di.container.ts#L248


haseebrabbani commented 1 year ago

to switch between multiple chains in the same project, the recommended way is to use the --config flag to select a different json config file (default is forta.config.json). see the CLI reference here: https://docs.forta.network/en/latest/cli/#run