tencent cloud

Tencent Cloud Blockchain as a Service

Release Notes
Product Introduction
Overview
Product Features
Underlying Engine
Strengths
Scenarios
Basic Concepts
Purchase Guide
Purchase Page Description
Overdue Payment Instructions
Pricing and Specification Description
Getting Started
Hyperledger Fabric
Operation Guide
Consortium
Event Center
Network Overview
Connection Management
Contract Management
Organization Management
Node Management
Blockchain Browser
Certificate management
Audit Log
Node Monitoring and Logs
Development Guide
Hyperledger Fabric
Application System Integration
API Documentation
History
Introduction
API Category
Making API Requests
Hyperledger Fabric 2.3 APIs
Data Types
Error Codes
FAQs
Product Policy
Data Processing And Security Agreement
Contact Us

Go SDK

PDF
フォーカスモード
フォントサイズ
最終更新日: 2025-04-10 00:41:11

Overview

Welcome to use the TBaaS Product Developer Toolkit (SDK) 3.0. SDK 3.0 is a companion tool for the TencentCloud API 3.0 platform. To facilitate Go developers in debugging and integrating with the TBaaS product API, this section introduces the TBaaS product development toolkit suitable for Go and provides a simple example for first-time use of the development toolkit. This allows you to quickly obtain the TBaaS product Go SDK and start calling.

Dependent Environment

1. Dependent Environment: Go 1.9 or higher, and set required environment variables such as GOPATH.
2. Enable the TBaaS product through the Tencent Cloud console.
3. Obtain SecretID and SecretKey as well as the API call address (tbaas.tencentcloudapi.com).

Get Installation

Install Go SDK and before first-time use of TencentCloud API, users need to apply for and obtain security credentials in the Tencent Cloud console. Security credentials include SecretID and SecretKey. SecretID is used to identify the identity of the API caller, and SecretKey is used to encrypt signature strings and as the server-side verification key for signature strings. SecretKey must be kept safely to avoid leakage.

Install Via Go Get (Recommended)

Use the built-in tool to install the SDK.
go get -u github.com/tencentcloud/tencentcloud-sdk-go

Install Via Source Code Package

1. Go to the Github code hosting address to download the latest code.
2. Extract the obtained source code package and install it under the directory $GOPATH/src/github.com/tencentcloud.

API List

View the detailed API list in the API document.

Example

Take calling the Fabric user contract to execute a transaction (InvokeFabricChaincode) API as an example:
package main

import (
"fmt"

"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
tbaas "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tbaas/v20180416"
)

func main() {
// Instantiate an authentication object. Input parameters need to be passed in with the SecretId and SecretKey of your Tencent Cloud account. Here, you also need to pay attention to keeping the confidentiality of the key pair.
credential := common.NewCredential(
"",
"",
)
// Instantiate a client option, optional, which can be skipped if there is no special requirement.
cpf := profile.NewClientProfile()
cpf.HttpProfile.Endpoint = "tbaas.intl.tencentcloudapi.com"
// Instantiate the client object to request the product, and clientProfile is optional.
client, _ := tbaas.NewClient(credential, "ap-hongkong", cpf)

// Instantiate a request object. Each interface will correspond to a request object.
request := tbaas.NewInvokeFabricChaincodeRequest()

request.ClusterId = common.StringPtr("fabric-65z42qi150")
request.ChannelId = common.StringPtr("channel-9xej4d")
request.ChaincodeName = common.StringPtr("fact")
request.FuncName = common.StringPtr("Set")
request.FuncParam = common.StringPtrs([]string{ "key", "value" })
request.WithAsyncResult = common.BoolPtr(false)
// The returned resp is an instance of InvokeFabricChaincodeResponse, corresponding to the request object.
response, err := client.InvokeFabricChaincode(request)
if _, ok := err.(*errors.TencentCloudSDKError); ok {
fmt.Printf("An API error has returned: %s", err)
return
}
if err != nil {
panic(err)
}
// Output string in json format.
fmt.Printf("%s", response.ToJsonString())
}


ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック