Skip to main content

DeployContract gRPC Method

Loading...

Updated on
May 13, 2025

DeployContract gRPC Method

Parameters

from
string
REQUIRED
Loading...
contractName
string
REQUIRED
Loading...
abi
object
REQUIRED
Loading...
codeStr
string
REQUIRED
Loading...
feeLimit
integer
REQUIRED
Loading...
curPercent
integer
REQUIRED
Loading...
oeLimit
integer
REQUIRED
Loading...

Returns

transaction
object
Loading...
raw_data
object
Loading...
ref_block_bytes
string
Loading...
ref_block_num
integer
Loading...
ref_block_hash
string
Loading...
expiration
integer
Loading...
auths
array
Loading...
data
string
Loading...
contract
array
Loading...
type
string
Loading...
parameter
object
Loading...
value
string
Loading...
type_url
string
Loading...
provider
string
Loading...
ContractName
string
Loading...
Permission_id
integer
Loading...
scripts
string
Loading...
timestamp
integer
Loading...
fee_limit
integer
Loading...
signature
array
Loading...
ret
array
Loading...
fee
integer
Loading...
ret
string
Loading...
contractRet
string
Loading...
assetIssueID
string
Loading...
withdraw_amount
integer
Loading...
unfreeze_amount
integer
Loading...
exchange_received_amount
integer
Loading...
exchange_inject_another_amount
integer
Loading...
exchange_withdraw_another_amount
integer
Loading...
exchange_id
integer
Loading...
shielded_transaction_fee
integer
Loading...
orderId
string
Loading...
orderDetails
array
Loading...
makerOrderId
string
Loading...
takerOrderId
string
Loading...
fillSellQuantity
integer
Loading...
fillBuyQuantity
integer
Loading...
withdraw_expire_amount
integer
Loading...
cancelUnfreezeV2Amount
object
Loading...
txid
string
Loading...
constant_result
array
Loading...
result
object
Loading...
result
boolean
Loading...
code
string
Loading...
message
string
Loading...
energy_used
integer
Loading...
logs
array
Loading...
address
string
Loading...
topics
array
Loading...
data
string
Loading...
internal_transactions
array
Loading...
hash
string
Loading...
caller_address
string
Loading...
transferTo_address
string
Loading...
callValueInfo
array
Loading...
callValue
integer
Loading...
tokenId
string
Loading...
note
string
Loading...
rejected
boolean
Loading...
extra
string
Loading...
energy_penalty
integer
Loading...
Request
1
package main
2
3
import (
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
)
13
14
// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token
15
// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde123456789
16
// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}
17
// token will be : abcde123456789
18
19
var token = "YOUR_TOKEN"
20
var endpoint = "YOUR_ENDPOINT:50051"
21
22
type auth struct {
23
token string
24
}
25
26
func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
27
return map[string]string{
28
"x-token": a.token,
29
}, nil
30
}
31
32
func (a *auth) RequireTransportSecurity() bool {
33
return false
34
}
35
36
func main() {
37
38
opts := []grpc.DialOption{
39
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
40
grpc.WithPerRPCCredentials(&auth{token}),
41
}
42
conn := client.NewGrpcClient(endpoint)
43
if err := conn.Start(opts...); err != nil {
44
panic(err)
45
}
46
defer conn.Conn.Close()
47
48
from := "TJmmqjb1DK9TTZbQXzRQ2AuA94z4gKAPFh"
49
contractName := "SomeContract"
50
codeStr := "608060405234801561001057600080fd5b5060de8061001f6000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631ab06ee58114604d5780639507d39a146067575b600080fd5b348015605857600080fd5b506065600435602435608e565b005b348015607257600080fd5b50607c60043560a0565b60408051918252519081900360200190f35b60009182526020829052604090912055565b600090815260208190526040902054905600a165627a7a72305820fdfe832221d60dd582b4526afa20518b98c2e1cb0054653053a844cf265b25040029"
51
feeLimit := int64(1000000000) // 1000 TRX maximum fee
52
curPercent := int64(100) // Use 100% of caller's resource
53
oeLimit := int64(10000000) // Energy limit for the contract
54
55
abiEntries := []*core.SmartContract_ABI_Entry{
56
{
57
Name: "set",
58
Inputs: []*core.SmartContract_ABI_Entry_Param{
59
{Name: "key", Type: "uint256"},
60
{Name: "value", Type: "uint256"},
61
},
62
Type: core.SmartContract_ABI_Entry_Function,
63
},
64
{
65
Name: "get",
66
Inputs: []*core.SmartContract_ABI_Entry_Param{
67
{Name: "key", Type: "uint256"},
68
},
69
Outputs: []*core.SmartContract_ABI_Entry_Param{
70
{Name: "value", Type: "uint256"},
71
},
72
Type: core.SmartContract_ABI_Entry_Function,
73
},
74
}
75
76
abi := &core.SmartContract_ABI{
77
Entrys: abiEntries,
78
}
79
80
fmt.Println("Creating contract deployment transaction...")
81
82
tx, err := conn.DeployContract(
83
from, // Deployer's address
84
contractName, // Contract name
85
abi, // ABI struct
86
codeStr, // Contract bytecode
87
feeLimit, // Fee limit
88
curPercent, // Resource consumption percentage
89
oeLimit, // Energy limit
90
)
91
92
if err != nil {
93
fmt.Printf("Error creating contract deployment transaction: %v\n", err)
94
return
95
}
96
97
fmt.Println("Contract deployment transaction created successfully. Transaction details:")
98
jsonData, _ := json.MarshalIndent(tx, "", " ")
99
fmt.Println(string(jsonData))
100
101
// NOTE: In a production environment, the transaction should be signed here
102
fmt.Println("\nBroadcasting transaction to the TRON network...")
103
result, err := conn.Broadcast(tx.Transaction)
104
if err != nil {
105
fmt.Printf("Error broadcasting transaction: %v\n", err)
106
return
107
}
108
109
if !result.GetResult() {
110
fmt.Printf("Broadcast failed: %s\n", result.GetMessage())
111
return
112
}
113
114
fmt.Println("Contract deployment successful! Result:")
115
resultJSON, _ := json.MarshalIndent(result, "", " ")
116
fmt.Println(string(resultJSON))
117
fmt.Println("\nContract address can be retrieved after the transaction is confirmed.")
118
}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free