DeployContract gRPC Method
參數
來自
字串
必填
載入中...
contractName
字串
必填
載入中...
abi
物件
必填
載入中...
codeStr
字串
必填
載入中...
feeLimit
整數
必填
載入中...
curPercent
整數
必填
載入中...
oeLimit
整數
必填
載入中...
退貨
交易
物件
載入中...
raw_data
物件
載入中...
ref_block_bytes
字串
載入中...
ref_block_num
整數
載入中...
ref_block_hash
字串
載入中...
expiration
整數
載入中...
auths
陣列
載入中...
資料
字串
載入中...
合約
陣列
載入中...
類型
字串
載入中...
parameter
物件
載入中...
值
字串
載入中...
type_url
字串
載入中...
provider
字串
載入中...
ContractName
字串
載入中...
Permission_id
整數
載入中...
scripts
字串
載入中...
時間戳記
整數
載入中...
fee_limit
整數
載入中...
簽名
陣列
載入中...
ret
陣列
載入中...
fee
整數
載入中...
ret
字串
載入中...
contractRet
字串
載入中...
assetIssueID
字串
載入中...
withdraw_amount
整數
載入中...
unfreeze_amount
整數
載入中...
exchange_received_amount
整數
載入中...
exchange_inject_another_amount
整數
載入中...
exchange_withdraw_another_amount
整數
載入中...
exchange_id
整數
載入中...
shielded_transaction_fee
整數
載入中...
orderId
字串
載入中...
orderDetails
陣列
載入中...
makerOrderId
字串
載入中...
takerOrderId
字串
載入中...
fillSellQuantity
整數
載入中...
fillBuyQuantity
整數
載入中...
withdraw_expire_amount
整數
載入中...
cancelUnfreezeV2Amount
物件
載入中...
txid
字串
載入中...
constant_result
陣列
載入中...
結果
物件
載入中...
結果
布林值
載入中...
程式碼
字串
載入中...
訊息
字串
載入中...
energy_used
整數
載入中...
日誌
陣列
載入中...
地址
字串
載入中...
主題
陣列
載入中...
資料
字串
載入中...
internal_transactions
陣列
載入中...
hash
字串
載入中...
caller_address
字串
載入中...
transferTo_address
字串
載入中...
callValueInfo
陣列
載入中...
callValue
整數
載入中...
tokenId
字串
載入中...
註
字串
載入中...
rejected
布林值
載入中...
extra
字串
載入中...
energy_penalty
整數
載入中...
請求
1package main23import (4"context"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 endpoint = "YOUR_ENDPOINT:50051"2122type auth struct {23token string24}2526func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, 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)94return95}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)106return107}108109if !result.GetResult() {110fmt.Printf("Broadcast failed: %s\n", result.GetMessage())111return112}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}
1package main23import (4"context"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 endpoint = "YOUR_ENDPOINT:50051"2122type auth struct {23token string24}2526func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, 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)94return95}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)106return107}108109if !result.GetResult() {110fmt.Printf("Broadcast failed: %s\n", result.GetMessage())111return112}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}