DeployContract gRPC Method
参数
来自
字符串
必填
正在加载...
contractName
字符串
必填
正在加载...
abi
对象
必填
正在加载...
codeStr
字符串
必填
正在加载...
feeLimit
整数
必填
正在加载...
curPercent
整数
必填
正在加载...
oeLimit
整数
必填
正在加载...
退货
交易
对象
正在加载...
原始数据
对象
正在加载...
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() {3738opts := []grpc.DialOption{39grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),40grpc.WithPerRPCCredentials(&auth{token}),41}42conn := client.NewGrpcClient(endpoint)43if err := conn.Start(opts...); err != nil {44panic(err)45}46defer conn.Conn.Close()4748from := "TJmmqjb1DK9TTZbQXzRQ2AuA94z4gKAPFh"49contractName := "SomeContract"50codeStr := "608060405234801561001057600080fd5b5060de8061001f6000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631ab06ee58114604d5780639507d39a146067575b600080fd5b348015605857600080fd5b506065600435602435608e565b005b348015607257600080fd5b50607c60043560a0565b60408051918252519081900360200190f35b60009182526020829052604090912055565b600090815260208190526040902054905600a165627a7a72305820fdfe832221d60dd582b4526afa20518b98c2e1cb0054653053a844cf265b25040029"51feeLimit := int64(1000000000) // 1000 TRX maximum fee52curPercent := int64(100) // Use 100% of caller's resource53oeLimit := int64(10000000) // Energy limit for the contract5455abiEntries := []*core.SmartContract_ABI_Entry{56{57Name: "set",58Inputs: []*core.SmartContract_ABI_Entry_Param{59{Name: "key", Type: "uint256"},60{Name: "value", Type: "uint256"},61},62Type: core.SmartContract_ABI_Entry_Function,63},64{65Name: "get",66Inputs: []*core.SmartContract_ABI_Entry_Param{67{Name: "key", Type: "uint256"},68},69Outputs: []*core.SmartContract_ABI_Entry_Param{70{Name: "value", Type: "uint256"},71},72Type: core.SmartContract_ABI_Entry_Function,73},74}7576abi := &core.SmartContract_ABI{77Entrys: abiEntries,78}7980fmt.Println("Creating contract deployment transaction...")8182tx, err := conn.DeployContract(83from, // Deployer's address84contractName, // Contract name85abi, // ABI struct86codeStr, // Contract bytecode87feeLimit, // Fee limit88curPercent, // Resource consumption percentage89oeLimit, // Energy limit90)9192if err != nil {93fmt.Printf("Error creating contract deployment transaction: %v\n", err)94返回95}9697fmt.Println("Contract deployment transaction created successfully. Transaction details:")98jsonData, _ := json.MarshalIndent(tx, "", " ")99fmt.Println(string(jsonData))100101// NOTE: In a production environment, the transaction should be signed here102fmt.Println("\nBroadcasting transaction to the TRON network...")103result, err := conn.Broadcast(tx.Transaction)104if err != nil {105fmt.Printf("Error broadcasting transaction: %v\n", err)106返回107}108109if !result.GetResult() {110fmt.Printf("Broadcast failed: %s\n", result.GetMessage())111返回112}113114fmt.Println("Contract deployment successful! Result:")115resultJSON, _ := json.MarshalIndent(result, "", " ")116fmt.Println(string(resultJSON))117fmt.Println("\nContract address can be retrieved after the transaction is confirmed.")118}
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() {3738opts := []grpc.DialOption{39grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),40grpc.WithPerRPCCredentials(&auth{token}),41}42conn := client.NewGrpcClient(endpoint)43if err := conn.Start(opts...); err != nil {44panic(err)45}46defer conn.Conn.Close()4748from := "TJmmqjb1DK9TTZbQXzRQ2AuA94z4gKAPFh"49contractName := "SomeContract"50codeStr := "608060405234801561001057600080fd5b5060de8061001f6000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631ab06ee58114604d5780639507d39a146067575b600080fd5b348015605857600080fd5b506065600435602435608e565b005b348015607257600080fd5b50607c60043560a0565b60408051918252519081900360200190f35b60009182526020829052604090912055565b600090815260208190526040902054905600a165627a7a72305820fdfe832221d60dd582b4526afa20518b98c2e1cb0054653053a844cf265b25040029"51feeLimit := int64(1000000000) // 1000 TRX maximum fee52curPercent := int64(100) // Use 100% of caller's resource53oeLimit := int64(10000000) // Energy limit for the contract5455abiEntries := []*core.SmartContract_ABI_Entry{56{57Name: "set",58Inputs: []*core.SmartContract_ABI_Entry_Param{59{Name: "key", Type: "uint256"},60{Name: "value", Type: "uint256"},61},62Type: core.SmartContract_ABI_Entry_Function,63},64{65Name: "get",66Inputs: []*core.SmartContract_ABI_Entry_Param{67{Name: "key", Type: "uint256"},68},69Outputs: []*core.SmartContract_ABI_Entry_Param{70{Name: "value", Type: "uint256"},71},72Type: core.SmartContract_ABI_Entry_Function,73},74}7576abi := &core.SmartContract_ABI{77Entrys: abiEntries,78}7980fmt.Println("Creating contract deployment transaction...")8182tx, err := conn.DeployContract(83from, // Deployer's address84contractName, // Contract name85abi, // ABI struct86codeStr, // Contract bytecode87feeLimit, // Fee limit88curPercent, // Resource consumption percentage89oeLimit, // Energy limit90)9192if err != nil {93fmt.Printf("Error creating contract deployment transaction: %v\n", err)94返回95}9697fmt.Println("Contract deployment transaction created successfully. Transaction details:")98jsonData, _ := json.MarshalIndent(tx, "", " ")99fmt.Println(string(jsonData))100101// NOTE: In a production environment, the transaction should be signed here102fmt.Println("\nBroadcasting transaction to the TRON network...")103result, err := conn.Broadcast(tx.Transaction)104if err != nil {105fmt.Printf("Error broadcasting transaction: %v\n", err)106返回107}108109if !result.GetResult() {110fmt.Printf("Broadcast failed: %s\n", result.GetMessage())111返回112}113114fmt.Println("Contract deployment successful! Result:")115resultJSON, _ := json.MarshalIndent(result, "", " ")116fmt.Println(string(resultJSON))117fmt.Println("\nContract address can be retrieved after the transaction is confirmed.")118}