Use API Endpoint

Most of the interaction with the API is achieved by calling the JSON-RPC method.

Whether or not authentication is required depends on the authentication method selected when creating the API.

The JSON-RPC method of different nodes will be different, please refer to the specific API for details. The following is a list of APIs we support

BSC simple example

We take BSC as an example, the call is as follows, for reference only

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/binance/full/main"    // authentication
    const url_token = "https://apis.ankr.com/xxxxx/xxxxx/binance/full/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)
}
const Web3 = require('web3');


let url_auth = 'https://username:password@apis.ankr.com/xxxxx/xxxxx/binance/full/main'  // authentication
let url_token = 'https://apis.ankr.com/xxxxx/xxxxx/binance/full/main'   // token

const web3 = new Web3(new Web3.providers.HttpProvider('choose url_auth or url_token by your created type'));

web3.eth.getBlockNumber((error, blockNumber) => {
    if(!error){
        console.log(blockNumber);
    }else{
        console.log(error);
    }
})
from web3 import Web3


def test_block_number(self):
    url_auth = 'https://username:password@apis.ankr.com/xxxxx/xxxxx/binance/full/main'  # authentication
    url_token = 'https://apis.ankr.com/xxxxx/xxxxx/binance/full/main'   # token
    
    web3 = Web3(HTTPProvider('choose url_auth or url_token by your created type'))
    print(web3.eth.block_number)
# authentication
$ curl -H "Content-Type: application/json" -u "username:password" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://apis.ankr.com/xxxxx/xxxxx/binance/full/main

# token
$ curl -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://apis.ankr.com/xxxxx/xxxxx/binance/full/main

Wss endpoint

package main

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


func main() {
    const url_auth = "wss://username:password@apis.ankr.com/wss/xxxxx/xxxxx/binance/full/main"  // authentication
    const url_token = "wss://apis.ankr.com/wss/xxxxx/xxxxx/binance/full/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)
}
const Web3 = require('web3');


let url_auth = "wss://username:password@apis.ankr.com/wss/xxxxx/xxxxx/binance/full/main";   // authentication
let url_token = "wss://apis.ankr.com/wss/xxxxx/xxxxx/binance/full/main";    // token

let web3 = new Web3(new Web3.providers.WebsocketProvider('choose url_auth or url_token by your created type'));

web3.eth.getBlockNumber((error, blockNumber) => {
    if (!error) {
        console.log(blockNumber)
    } else {
        console.log(error)
    }
})

console.log("wait start")

setTimeout(function () {
    console.log("wait end")
    web3.eth.clearSubscriptions((error, result) => {
        if (!error) {
            console.log(result)
        } else {
            console.log(error)
        }
    })
    web3.currentProvider.disconnect()
}, 3000);
from web3 import Web3


def test_block_number(self):
    url_auth = 'wss://username:password@apis.ankr.com/wss/xxxxx/xxxxx/binance/full/main' # authentication
    url_token = 'wss://apis.ankr.com/wss/xxxxx/xxxxx/binance/full/main' # token
    
    web3 = Web3(WebsocketProvider('choose url_auth or url_token by your created type'))
    print(web3.eth.block_number)
# authentication
$ wscat -c wss://username:password@apis.ankr.com/wss/xxxxx/xxxxx/binance/full/main
> {"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}

# token
$ wscat -c wss://apis.ankr.com/wss/xxxxx/xxxxx/binance/full/main
> {"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}