Installation

Requirements

Please note that an official binary distribution is not available at the moment. To build your own GraphQL API, you need to have the following:

You do have another option. For initial testing and development, you can use our own testing playground. The API server is deployed at https://xapi2.fantom.network/api for regular GraphQL queries and at https://xapi2.fantom.network/graphql for WebSocket subscriptions.

Feel free to connect and try your queries. Fine-tune your application before committing to deploying your own instance.

Building Process

Building your API server is a fairly straightforward process. First, clone the repository to your local machine. Do not clone the project into $GOPATH, due to the Go modules. Instead, use any other location.

$ git clone https://github.com/Fantom-foundation/fantom-api-graphql.git

Once you have the copy on your machine, build the executable:

$ cd fantom-api-graphql
$ go build -o ./build/apiserver ./cmd/apiserver

The API server executable will be created in the <build> folder of the project. You can change the location by changing the output path in the Go building command above.

To run your copy of the API server, simply run:

$ build/apiserver

Configuration

The API server already contains some most common configuration options as default values, and you don't have to change them most of the time. The default values are:

  • Network binding address is localhost.

  • Default listening port is 16761.

  • Default Lachesis IPC interface is ~/.lachesis/data/lachesis.ipc.

  • MongoDB connection address is mongodb://localhost:27017.

  • Default logging level is INFO.

If you want to change one of the default values, you need to create a configuration file. The API server can read configuration options from several configuration formats, namely JSON, TOML, YAML, HCL, envfile, and Java properties config files.

Please choose the one you are most familiar with. The name of the configuration file is expected to be "apiserver" with an extension that corresponds with the file format of your choosing.

Example YAML file looks like this:

server:
    bind: 127.0.0.1:16761    
lachesis:
    url: /var/opera/data/lachesis.ipc
log:
    level: Debug
mongo:
    url: mongodb://127.0.0.1:27017
cors:
    origins: *

You can keep the config file in the same location as the API server executable, or you can save it in the home folder under the .fantomapi sub-folder. On MacOS, the expected path is Library/FantomApi.

Last updated

© 2024 Sonic Labs