Ankr Docs
Search…
Develop on OKExChain
Ankr allows users to create their own OKExChain full and archive 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 OKExChain

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

** Network Types**

  • Mainnet
  • Testnet

Nodes

  • OKExChain Full
  • OKExChain Archive

Explorers

Official OKEx Explorer: https://www.oklink.com/okexchain

JSON RPC & API Docs

Example Calls

API (HTTPS) Endpoint

Go
Javascript
Python
Curl
1
package main
2
3
import (
4
"context"
5
"fmt"
6
"github.com/ethereum/go-ethereum/ethclient"
7
)
8
9
10
func main() {
11
const url_auth = "https://username:[email protected]/xxxxx/xxxxx/okexchain/full/main" // authentication
12
const url_token = "https://apis.ankr.com/xxxxx/xxxxx/okexchain/full/main" // token
13
14
rpcClient,err := ethclient.Dial("choose url_auth or url_token by your created type")
15
16
if err != nil {
17
panic(err)
18
}
19
20
blockNumber, err := rpcClient.BlockNumber(context.Background())
21
22
if err != nil {
23
panic(err)
24
}
25
26
fmt.Println(blockNumber)
27
}
Copied!
1
const Web3 = require('web3');
2
3
4
const url_auth = 'https://username:[email protected]/xxxxx/xxxxx/okexchain/full/main' // authentication
5
const url_token = 'https://apis.ankr.com/xxxxx/xxxxx/okexchain/full/main' // token
6
7
const web3 = new Web3(new Web3.providers.HttpProvider('choose url_auth or url_token by your created type'));
8
9
web3.eth.getBlockNumber((error, blockNumber) => {
10
if(!error){
11
console.log(blockNumber);
12
}else{
13
console.log(error);
14
}
15
})
Copied!
1
from web3 import Web3
2
3
4
def test_block_number(self):
5
url_auth = 'https://username:[email protected]/xxxxx/xxxxx/okexchain/full/main' # authentication
6
url_token = 'https://apis.ankr.com/xxxxx/xxxxx/okexchain/full/main' # token
7
8
web3 = Web3(HTTPProvider('choose url_auth or url_token by your created type'))
9
print(web3.eth.block_number)
Copied!
1
# authentication
2
$ 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/okexchain/full/main
3
$ curl -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://username:[email protected]/xxxxx/xxxxx/okexchain/full/main
4
5
# token
6
$ curl -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://apis.ankr.com/xxxxx/xxxxx/okexchain/full/main
Copied!

Websocket (WSS) Endpoint

Go
Javascript (ethers)
Javascript (ws)
Curl
1
package main
2
3
import (
4
"context"
5
"fmt"
6
"github.com/ethereum/go-ethereum/core/types"
7
"github.com/ethereum/go-ethereum/ethclient"
8
"time"
9
)
10
11
12
func main() {
13
const url_auth = "wss://username:[email protected]/wss/xxxxx/xxxxx/okexchain/full/main" // authentication
14
const url_token = "wss://apis.ankr.com/wss/xxxxx/xxxxx/okexchain/full/main" // token
15
16
client, err := ethclient.Dial(`choose url_auth or url_token by your created type`)
17
18
if err != nil {
19
panic(err)
20
}
21
22
ch := make(chan *types.Header, 1024)
23
sub, err := client.SubscribeNewHead(context.Background(), ch)
24
25
if err != nil {
26
panic(err)
27
}
28
29
fmt.Println("---subscribe-----")
30
31
go func() {
32
time.Sleep(10 * time.Second)
33
fmt.Println("---unsubscribe-----")
34
sub.Unsubscribe()
35
}()
36
37
go func() {
38
for c := range ch {
39
fmt.Println(c.Number)
40
}
41
}()
42
43
<-sub.Err()
44
45
}
Copied!
1
const ethers = require("ethers");
2
3
const url_auth = 'wss://username:[email protected]/wss/xxxxx/xxxxx/okexchain/full/main' // authentication
4
const url_token = 'wss://[email protected]/wss/xxxxx/xxxxx/okexchain/full/main' // token
5
6
const init = function () {
7
8
const wsProvider = new ethers.providers.WebSocketProvider('choose url_auth or url_token by your created type');
9
10
wsProvider.on("pending", (tx) => {
11
console.log("tx", tx)
12
setTimeout(function () {
13
wsProvider.destroy()
14
}, 1000);
15
16
});
17
18
};
19
20
init();
Copied!
1
const WebSocket = require('ws');
2
3
const url_auth = 'wss://username:[email protected]/wss/xxxxx/xxxxx/okexchain/full/main' // authentication
4
const url_token = 'wss://[email protected]/wss/xxxxx/xxxxx/okexchain/full/main' // token
5
6
const request = '{"id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}';
7
8
const ws = new WebSocket('choose url_auth or url_token by your created type');
9
10
ws.on('open', function open() {
11
ws.send(request);
12
});
13
ws.on('message', function incoming(data) {
14
res = JSON.parse(data)
15
if (res.result != null) {
16
console.log(`Subscription: ${res.result}`);
17
} else if (res.params != null && res.params["result"] != null) {
18
console.log(`New pending transaction: ${res.params["result"]}`);
19
} else {
20
console.log(`Unexpected: ${data}`);
21
}
22
});
Copied!
1
# authentication
2
$ wscat -c wss://username:[email protected]/wss/xxxxx/xxxxx/okexchain/full/main
3
4
# token
5
$ wscat -c wss://apis.ankr.com/wss/xxxxx/xxxxx/okexchain/full/main
6
7
wait connected...
8
9
# subscribe
10
> {"jsonrpc":"2.0","method":"eth_subscribe","params":["newHeads"],"id":1}
11
12
# unsubscribe
13
> {"jsonrpc":"2.0","method":"eth_unsubscribe","params":["0xxxxxxxxxxxxxxx"],"id":1}
Copied!
Last modified 1mo ago