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

Java SDK

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 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 Java developers in debugging and integrating with the TBaaS Product API, this section introduces the TBaaS Product Development Kit for Java and provides a simple example for first-time use of the development kit. This allows you to quickly obtain the TBaaS Product Java SDK and start making API calls.

Dependent Environment

1. Dependent Environment: JDK 7 or higher.
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 Java 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. SecretKey is used to encrypt signature strings and is the server-side verification key for signature strings. SecretKey must be kept safely to avoid leakage.

Install Via Maven (Recommended)

The Java SDK is recommended to be installed via Maven. Maven is a dependency management tool for Java. It supports the dependencies required by your project and installs them into the project. For detailed information about Maven, refer to Maven Official Website.
1. Go to Maven official website to download the Maven installation package for the corresponding system and initiate installation.
2. Add the following content to the Maven pom.xml to add Maven dependencies for your project.
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId>
<version>3.0.1</version>
</dependency>
Notes:
<version> The version number in the tag is a reference example. Find the latest version on the Maven repository and fill in.

Install Via a Source - Code Package

1. Go to the Github code hosting address to download the source code package.
2. Decompress the obtained source code package to a suitable location of your project.
3. Copy the jar packages under the vendor directory to a path where Java can find them.

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 com.tencent;
import com.tencentcloudapi.common.AbstractModel;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.tbaas.v20180416.TbaasClient;
import com.tencentcloudapi.tbaas.v20180416.models.*;

public class Sample
{
public static void main(String [] args) {
try{
// 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 cred = new Credential("", "");
// Instantiate an HTTP option, optional, which can be skipped if there is no special requirement.
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("tbaas.intl.tencentcloudapi.com");
// Instantiate a client option, optional, which can be skipped if there is no special requirement.
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
// Instantiate the client object to request the product, and clientProfile is optional.
TbaasClient client = new TbaasClient(cred, "ap-hongkong", clientProfile);
// Instantiate a request object. Each interface will correspond to a request object.
InvokeFabricChaincodeRequest req = new InvokeFabricChaincodeRequest();
req.setClusterId("fabric-65z42qi150");
req.setChannelId("channel-9xej4d");
req.setChaincodeName("fact");
req.setFuncName("Set");

String[] funcParam1 = {"key", "value"};
req.setFuncParam(funcParam1);

req.setWithAsyncResult(false);
// The returned resp is an instance of InvokeFabricChaincodeResponse, corresponding to the requested object.
InvokeFabricChaincodeResponse resp = client.InvokeFabricChaincode(req);
// Output string in json format.
System.out.println(AbstractModel.toJsonString(resp));
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}
}
}


Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan