Skip to main content

XDai API

Develop on xDai

Ankr allows users to create their own full and archive xDai Stablechain APIs with a variety of options for request call limits, archived data, and more. Ankr’s novel cluster technology allows APIs to draw from multiple nodes, offering a more reliable experience for our users. \

Get started on xDai

  1. Login or set up an account on app.ankr.com
  2. Create API

Network types available on Ankr

  • Mainnet

Node modes available on Ankr

  • Full
  • Archive

BlockScout info

GraphQL: https://blockscout.com/poa/xdai/graphiql

XDAI uses standard JSON RPC methods.

View Supported JSON RPC Methods

Postman: https://documenter.getpostman.com/view/4117254/ethereum-json-rpc/RVu7CT5J?version=latest

RPC: https://blockscout.com/xdai/mainnet/api-docs

Eth RPC: https://blockscout.com/xdai/mainnet/eth-rpc-api-docs\ \ Gas Price Oracle: https://blockscout.com/xdai/mainnet/api/v1/gas-price-oracle

Example calls

API HTTPS endpoint

package main

import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/ethclient"
)

func main() {
const url_auth = "https://username:password@apis.ankr.com/xxxxx/xxxxx/xdai/fast/main" // authentication
const url_token = "https://apis.ankr.com/xxxxx/xxxxx/xdai/fast/main" // token

rpcClient,err := ethclient.Dial("choose url_auth or url_token by your created type")

if err != nil {
panic(err)
}

blockNumber, err := rpcClient.BlockNumber(context.Background())

if err != nil {
panic(err)
}

fmt.Println(blockNumber)
}

Websocket endpoint

package main

import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"time"
)

func main() {
const url_auth = "wss://username:password@apis.ankr.com/wss/xxxxx/xxxxx/xdai/fast/main" // authentication
const url_token = "wss://apis.ankr.com/wss/xxxxx/xxxxx/xdai/fast/main" // token

client, err := ethclient.Dial(`choose url_auth or url_token by your created type`)

if err != nil {
panic(err)
}

ch := make(chan *types.Header, 1024)
sub, err := client.SubscribeNewHead(context.Background(), ch)

if err != nil {
panic(err)
}

fmt.Println("---subscribe-----")

go func() {
time.Sleep(10 * time.Second)
fmt.Println("---unsubscribe-----")
sub.Unsubscribe()
}()

go func() {
for c := range ch {
fmt.Println(c.Number)
}
}()

<-sub.Err()

}