JSON-RPC API
This page contains all Boost API definitions. Interfaces defined here are exposed as JSON-RPC 2.0 endpoints by the boostd daemon.
To use the Boost Go client, the Go RPC-API library can be used to interact with the Boost API node.
- 1.Import the necessary Go module:
go get github.com/filecoin-project/go-jsonrpc
- 1.Create the following script:
package main
​
import (
"context"
"fmt"
"log"
"net/http"
​
jsonrpc "github.com/filecoin-project/go-jsonrpc"
boostapi "github.com/filecoin-project/boost/api"
)
​
func main() {
authToken := "<value found in ~/.boost/token>"
headers := http.Header{"Authorization": []string{"Bearer " + authToken}}
addr := "127.0.0.1:1288"
​
var api boostapi.BoostStruct
closer, err := jsonrpc.NewMergeClient(context.Background(), "ws://"+addr+"/rpc/v0", "Filecoin", []interface{}{&api.Internal, &api.CommonStruct.Internal}, headers)
if err != nil {
log.Fatalf("connecting with boost failed: %s", err)
}
defer closer()
​
// Now you can call any API you're interested in.
netAddrs, err := api.NetAddrsListen(context.Background())
if err != nil {
log.Fatalf("calling netAddrsListen: %s", err)
}
fmt.Printf("Boost is listening on: %s", netAddrs.Addrs[0])
}
- 1.Run
go mod init
to set up yourgo.mod
file - 2.You should now be able to interact with the Boost API.
The JSON-RPC API can also be communicated with programmatically from other languages. Here is an example written in Python. Note that the
method
must be prefixed with Filecoin.
import requests
import json
​
def main():
url = "http://localhost:3051/rpc/v0"
headers = {'content-type': 'application/json', "Authorization": "Bearer <token>"}
payload = {
"method": "Filecoin.BoostOfflineDealWithData",
"params": [
"<deal-uuid>",
"<file-path>",
True
],
"jsonrpc": "2.0",
"id": 1,
}
response = requests.post(url, data=json.dumps(payload), headers=headers)
print(response.text)
​
if __name__ == "__main__":
main()