dydxprotocol / v4-clients

Other
74 stars 57 forks source link

Missing documentation of ValidatorConfig parameters #250

Closed generalzzd closed 1 month ago

generalzzd commented 1 month ago
   net = Network(
        env='mainnet',
        validator_config=ValidatorConfig(
            grpc_endpoint='https://dydx-mainnet-full-rpc.public.blastapi.io:443',  # or other node URL
            chain_id='dydx-mainnet-1',
            ssl_enabled=False,
            url_prefix="https://example.com/prefix",
            aerial_url="https://example.com/aerial"
        ),
        indexer_config=IndexerConfig(
            rest_endpoint='https://indexer.dydx.trade',
            websocket_endpoint='wss://indexer.dydx.trade/v4/ws',
        ),
        faucet_endpoint='',
    )
    client = IndexerClient('https://indexer.dydx.trade')
    wallet = ValidatorClient(net.validator_config)

    time_response = await client.utility.get_time()
    print(time_response)

I try to create a ValidatorClient, however, I find the newest api has two parameters of 'url_prefix' and 'aerial_url'. What is the usage of those two parameters? And could you please give us a example for mainnet connection? Thank you!

linear[bot] commented 1 month ago

GH-68 Missing documentation of ValidatorConfig parameters

samtin0x commented 1 month ago

Hi @generalzzd ,

The url_prefix and aerial_url parameters in the ValidatorConfig are used for configuring the connection to the dYdX chain.

  1. aerial_url: This typically matches the validator endpoint. Its purpose is to specify the URL for the Aerial API.
  2. url_prefix: either grpc or rest
from dydx4.clients import ValidatorClient
from dydx4.network import Network, ValidatorConfig, IndexerConfig

net = Network(
    env='mainnet',
    validator_config=ValidatorConfig(
        grpc_endpoint='dydx-grpc.publicnode.com:443',
        chain_id='dydx-mainnet-1',
        ssl_enabled=True,
        aerial_config_url='https://dydx-grpc.publicnode.com:443',
        aerial_grpc_or_rest_prefix="grpc"
    ),
    indexer_config=IndexerConfig(
        rest_endpoint='https://indexer.dydx.trade/',
        websocket_endpoint='wss://indexer.dydx.trade/v4/ws',
    ),
)

wallet = ValidatorClient(net.validator_config)

In this example, aerial_config_url is set to the same value as grpc_endpoint. The aerial_grpc_or_rest_prefix is set to "grpc" because we're using a gRPC endpoint. If you were using a REST endpoint, you would set this to "rest".

Here you have a working example: https://docs.dydx.exchange/api_integration-guides/setting_up_raspberry_pi_for_api_trading