tencent cloud

文档反馈

Request Blockchain RPC service

最后更新时间:2023-09-11 16:29:27
1. Select the Application that you want to use, and click View details.



2. Move to the bottom of the page, and configure the IP/Domain whitelist (Note: Without a whitelist, all IP addresses can use this token to call the RPC service. Adding a whitelist allows only the IP addresses in the whitelist to use this token to call the RPC service).

2.1 Add the IP/Domain whitelist: Enter the IP/Domain in the input box, and click the Add button.






2.2 Remove the IP/Domain whitelist: Click the cancel button for the corresponding IP/Domain in the whitelist.






3. Select the chain service, network, and other information you want to use, such as Mainnet in Ethereum.



4. Call the RPC service

4.1 Invoke the RPC service using command-line commands: copy the command in the example and paste it to the whitelist machine, then press Enter to execute it using curl/wscat commands.



4.2 Invoke the RPC service using code: Copy the RPC invocation address in the NETWORK ENDPOINTS and connect to it using HTTP or HTTPS.



Demo:
package test

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

func Test_ws(t *testing.T) {
chainUrl := ""
client, err := ethclient.Dial(chainUrl)
if err != nil {
log.Fatal(err)
}

query := ethereum.FilterQuery{}
logs := make(chan types.Log)
sub, err := client.SubscribeFilterLogs(context.Background(), query, logs)
if err != nil {
log.Fatal(err)
}
fmt.Printf("sub: %+v\\n", sub)

for {
select {
case err := <-sub.Err():
fmt.Printf("err: %+v", err)
case vLog := <-logs:
fmt.Printf("%+v\\n", vLog.BlockNumber)
}
}
fmt.Printf("client: %+v", client)
}

func Test_http(t *testing.T) {
chainUrl := ""
client, err := ethclient.Dial(chainUrl)
if err != nil {
log.Fatal(err)
}

height, err := client.BlockNumber(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("block height: %+v\\n", height)
fmt.Printf("client: %+v", client)
}

联系我们

联系我们,为您的业务提供专属服务。

技术支持

如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

7x24 电话支持