DelegateResource gRPC Method
参数
来自
字符串
必填
正在加载...
到
字符串
必填
正在加载...
resource
字符串
必填
正在加载...
delegateBalance
整数
必填
正在加载...
lock
布尔型
必填
正在加载...
lockPeriod
整数
必填
正在加载...
退货
交易
对象
正在加载...
原始数据
对象
正在加载...
ref_block_bytes
字符串
正在加载...
ref_block_num
整数
正在加载...
ref_block_hash
字符串
正在加载...
到期
整数
正在加载...
auths
数组
正在加载...
数据
字符串
正在加载...
合同
数组
正在加载...
类型
字符串
正在加载...
参数
对象
正在加载...
值
字符串
正在加载...
type_url
字符串
正在加载...
提供商
字符串
正在加载...
合同名称
字符串
正在加载...
Permission_id
整数
正在加载...
脚本
字符串
正在加载...
时间戳
整数
正在加载...
fee_limit
整数
正在加载...
签名
数组
正在加载...
ret
数组
正在加载...
费用
整数
正在加载...
ret
字符串
正在加载...
contractRet
字符串
正在加载...
资产问题ID
字符串
正在加载...
取款金额
整数
正在加载...
解冻金额
整数
正在加载...
exchange_received_amount
整数
正在加载...
exchange_inject_another_amount
整数
正在加载...
exchange_withdraw_another_amount
整数
正在加载...
exchange_id
整数
正在加载...
受保护的交易费
整数
正在加载...
订单编号
字符串
正在加载...
订单详情
数组
正在加载...
makerOrderId
字符串
正在加载...
takerOrderId
字符串
正在加载...
fillSellQuantity
整数
正在加载...
fillBuyQuantity
整数
正在加载...
取款_到期金额
整数
正在加载...
cancelUnfreezeV2Amount
对象
正在加载...
txid
字符串
正在加载...
常量结果
数组
正在加载...
结果
对象
正在加载...
结果
布尔型
正在加载...
代码
字符串
正在加载...
消息
字符串
正在加载...
energy_used
整数
正在加载...
日志
数组
正在加载...
地址
字符串
正在加载...
主题
数组
正在加载...
数据
字符串
正在加载...
内部交易
数组
正在加载...
哈希
字符串
正在加载...
caller_address
字符串
正在加载...
transferTo_address
字符串
正在加载...
callValueInfo
数组
正在加载...
callValue
整数
正在加载...
tokenId
字符串
正在加载...
注
字符串
正在加载...
被拒绝
布尔型
正在加载...
额外
字符串
正在加载...
能量消耗
整数
正在加载...
请求
1包 main23导入 (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8"github.com/fbsobreira/gotron-sdk/pkg/client"9"github.com/fbsobreira/gotron-sdk/pkg/proto/core"10"google.golang.org/grpc"11"google.golang.org/grpc/credentials"12)1314// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token15// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678916// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}17// token will be : abcde1234567891819var token = "YOUR_TOKEN"20var 端点 = "YOUR_ENDPOINT:50051"2122类型 auth 结构体 {23token string24}2526func (a *auth) GetRequestMetadata(ctx 上下文.上下文, uri ...字符串) (map[字符串]字符串, error) {27return map[string]string{28"x-token": a.token,29}, nil30}3132func (a *auth) RequireTransportSecurity() bool {33return false34}3536func main() {37/*38* IMPORTANT NOTES FOR DOCUMENTATION:39* 1. The DelegateResource method allows an account to delegate bandwidth or energy to another account.40* 2. The delegator retains ownership of the resources but allows another account to use them.41* 3. The delegation can be for either bandwidth (NET) or energy (CPU) resources.42* 4. The delegation can be locked for a specified period (minimum 3 days).43* 5. The owner account must have sufficient resources to delegate.44*45* PREREQUISITE:46* Before using DelegateResource, you must first freeze TRX for resources using FreezeBalanceV2.47* You can only delegate resources that you've previously frozen, and the delegation amount48* must be less than or equal to your available frozen resources of the specified type.49* Example:50* // First freeze TRX for bandwidth51* conn.FreezeBalanceV2(from, delegateBalance, core.ResourceCode_BANDWIDTH)52* // Then delegate a portion of those frozen resources53* conn.DelegateResource(from, to, core.ResourceCode_BANDWIDTH, delegateBalance, lock, lockPeriod)54*/55opts := []grpc.DialOption{56grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),57grpc.WithPerRPCCredentials(&auth{token}),58}59conn := client.NewGrpcClient(endpoint)60if err := conn.Start(opts...); err != nil {61panic(err)62}63defer conn.Conn.Close()6465from := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g"66to := "TFgY1uN8buRxAtV2r6Zy5sG3ACko6pJT1y"67delegateBalance := int64(1000000)68lockPeriod := int64(3)69lock := false70resource := core.ResourceCode_BANDWIDTH // For bandwidth delegation71// resource := core.ResourceCode_ENERGY // For energy delegation7273fmt.Println("Creating resource delegation transaction...")7475// NOTE: This will fail if the owner address doesn't have enough frozen bandwidth resources.76// You must first freeze TRX for bandwidth using FreezeBalanceV2 before delegating.7778tx, err := conn.DelegateResource(79from,80to,81resource,82delegateBalance,83lock,84lockPeriod,85)8687if err != nil {88fmt.Printf("Error creating resource delegation transaction: %v\n", err)89返回90}9192fmt.Println("Resource delegation transaction created successfully. Transaction details:")93jsonData, _ := json.MarshalIndent(tx, "", " ")94fmt.Println(string(jsonData))9596fmt.Println("\nBroadcasting transaction to the TRON network...")97result, err := conn.Broadcast(tx.Transaction)98if err != nil {99fmt.Printf("Error broadcasting transaction: %v\n", err)100返回101}102103if !result.GetResult() {104fmt.Printf("Broadcast failed: %s\n", result.GetMessage())105返回106}107108fmt.Println("Resource delegation successful! Result:")109resultJSON, _ := json.MarshalIndent(result, "", " ")110fmt.Println(string(resultJSON))111}
1包 main23导入 (4"上下文"5"crypto/tls"6"encoding/json"7"fmt"8"github.com/fbsobreira/gotron-sdk/pkg/client"9"github.com/fbsobreira/gotron-sdk/pkg/proto/core"10"google.golang.org/grpc"11"google.golang.org/grpc/credentials"12)1314// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token15// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678916// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}17// token will be : abcde1234567891819var token = "YOUR_TOKEN"20var 端点 = "YOUR_ENDPOINT:50051"2122类型 auth 结构体 {23token string24}2526func (a *auth) GetRequestMetadata(ctx 上下文.上下文, uri ...字符串) (map[字符串]字符串, error) {27return map[string]string{28"x-token": a.token,29}, nil30}3132func (a *auth) RequireTransportSecurity() bool {33return false34}3536func main() {37/*38* IMPORTANT NOTES FOR DOCUMENTATION:39* 1. The DelegateResource method allows an account to delegate bandwidth or energy to another account.40* 2. The delegator retains ownership of the resources but allows another account to use them.41* 3. The delegation can be for either bandwidth (NET) or energy (CPU) resources.42* 4. The delegation can be locked for a specified period (minimum 3 days).43* 5. The owner account must have sufficient resources to delegate.44*45* PREREQUISITE:46* Before using DelegateResource, you must first freeze TRX for resources using FreezeBalanceV2.47* You can only delegate resources that you've previously frozen, and the delegation amount48* must be less than or equal to your available frozen resources of the specified type.49* Example:50* // First freeze TRX for bandwidth51* conn.FreezeBalanceV2(from, delegateBalance, core.ResourceCode_BANDWIDTH)52* // Then delegate a portion of those frozen resources53* conn.DelegateResource(from, to, core.ResourceCode_BANDWIDTH, delegateBalance, lock, lockPeriod)54*/55opts := []grpc.DialOption{56grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),57grpc.WithPerRPCCredentials(&auth{token}),58}59conn := client.NewGrpcClient(endpoint)60if err := conn.Start(opts...); err != nil {61panic(err)62}63defer conn.Conn.Close()6465from := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g"66to := "TFgY1uN8buRxAtV2r6Zy5sG3ACko6pJT1y"67delegateBalance := int64(1000000)68lockPeriod := int64(3)69lock := false70resource := core.ResourceCode_BANDWIDTH // For bandwidth delegation71// resource := core.ResourceCode_ENERGY // For energy delegation7273fmt.Println("Creating resource delegation transaction...")7475// NOTE: This will fail if the owner address doesn't have enough frozen bandwidth resources.76// You must first freeze TRX for bandwidth using FreezeBalanceV2 before delegating.7778tx, err := conn.DelegateResource(79from,80to,81resource,82delegateBalance,83lock,84lockPeriod,85)8687if err != nil {88fmt.Printf("Error creating resource delegation transaction: %v\n", err)89返回90}9192fmt.Println("Resource delegation transaction created successfully. Transaction details:")93jsonData, _ := json.MarshalIndent(tx, "", " ")94fmt.Println(string(jsonData))9596fmt.Println("\nBroadcasting transaction to the TRON network...")97result, err := conn.Broadcast(tx.Transaction)98if err != nil {99fmt.Printf("Error broadcasting transaction: %v\n", err)100返回101}102103if !result.GetResult() {104fmt.Printf("Broadcast failed: %s\n", result.GetMessage())105返回106}107108fmt.Println("Resource delegation successful! Result:")109resultJSON, _ := json.MarshalIndent(result, "", " ")110fmt.Println(string(resultJSON))111}