更新时间:2023-11-27 GMT+08:00
使用gotron-sdk发送gRPC请求
![](https://support.huaweicloud.com/intl/zh-cn/devg-nes/public_sys-resources/caution_3.0-zh-cn.png)
gotron-sdk截止至版本2.3.0,默认方式创建gRPC client暂不支持gRPC solidity节点连接。
在节点页面下载证书,将压缩包内的ca.crt证书放在项目内的目录。
在sdk中配置gRPC endpoint,示例代码如下:
import ( "fmt" "google.golang.org/gRPC" "google.golang.org/gRPC/credentials" "github.com/fbsobreira/gotron-sdk/pkg/client" ) func main() { gRPCWalletEndpoint := "your-gRPC-endpoint" credential := "your-credential" caPath := "your-ca.crt-file-path" creds, err := credentials.NewClientTLSFromFile(caPath, "") if err != nil { fmt.Printf("failed to load credentials: %v\n", err) } gRPCWalletClient := client.NewgRPCClient(gRPCWalletEndpoint) gRPCWalletClient.SetAPIKey(credential) gRPCWalletClient.Start(gRPC.WithTransportCredentials(creds)) resp, err := gRPCWalletClient.GetNowBlock() if err != nil { fmt.Printf("failed to get now block: %v\n", err) } fmt.Println("wallet resp: ", resp) }
Response example:
父主题: gRPC请求示例