CreateWitness gRPC Method
Parameters
from
string
REQUIRED
Loading...
urlStr
string
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
1package main23import (4"context"5"crypto/tls"6"encoding/json"7"fmt"8"github.com/fbsobreira/gotron-sdk/pkg/client"9"google.golang.org/grpc"10"google.golang.org/grpc/credentials"11)1213// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token14// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678915// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}16// token will be : abcde1234567891718var token = "YOUR_TOKEN"19var endpoint = "YOUR_ENDPOINT:50051"2021type auth struct {22token string23}2425func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {26return map[string]string{27"x-token": a.token,28}, nil29}3031func (a *auth) RequireTransportSecurity() bool {32return false33}3435func main() {36/*37* 1. The CreateWitness method allows an account to apply to become a Super Representative (SR).38* 2. The account must have enough TRX (9999 TRX) to apply for SR candidacy.39*/40opts := []grpc.DialOption{41grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),42grpc.WithPerRPCCredentials(&auth{token}),43}44conn := client.NewGrpcClient(endpoint)45if err := conn.Start(opts...); err != nil {46panic(err)47}48defer conn.Conn.Close()4950// Using variable names that match the function signature51from := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g"52urlStr := "https://my-tron-witness-info.example.com"5354fmt.Println("Creating witness application transaction...")5556// Call CreateWitness with parameters matching the function signature:57// func (g *GrpcClient) CreateWitness(from, urlStr string) (*api.TransactionExtention, error)58tx, err := conn.CreateWitness(from, urlStr)5960if err != nil {61fmt.Printf("Error creating witness application transaction: %v\n", err)62return63}6465fmt.Println("Witness application transaction created successfully. Transaction details:")66jsonData, _ := json.MarshalIndent(tx, "", " ")67fmt.Println(string(jsonData))6869fmt.Println("\nBroadcasting transaction to the TRON network...")70result, err := conn.Broadcast(tx.Transaction)71if err != nil {72fmt.Printf("Error broadcasting transaction: %v\n", err)73return74}7576if !result.GetResult() {77fmt.Printf("Broadcast failed: %s\n", result.GetMessage())78return79}8081fmt.Println("Witness application successful! Result:")82resultJSON, _ := json.MarshalIndent(result, "", " ")83fmt.Println(string(resultJSON))84}
1package main23import (4"context"5"crypto/tls"6"encoding/json"7"fmt"8"github.com/fbsobreira/gotron-sdk/pkg/client"9"google.golang.org/grpc"10"google.golang.org/grpc/credentials"11)1213// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token14// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678915// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}16// token will be : abcde1234567891718var token = "YOUR_TOKEN"19var endpoint = "YOUR_ENDPOINT:50051"2021type auth struct {22token string23}2425func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {26return map[string]string{27"x-token": a.token,28}, nil29}3031func (a *auth) RequireTransportSecurity() bool {32return false33}3435func main() {36/*37* 1. The CreateWitness method allows an account to apply to become a Super Representative (SR).38* 2. The account must have enough TRX (9999 TRX) to apply for SR candidacy.39*/40opts := []grpc.DialOption{41grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),42grpc.WithPerRPCCredentials(&auth{token}),43}44conn := client.NewGrpcClient(endpoint)45if err := conn.Start(opts...); err != nil {46panic(err)47}48defer conn.Conn.Close()4950// Using variable names that match the function signature51from := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g"52urlStr := "https://my-tron-witness-info.example.com"5354fmt.Println("Creating witness application transaction...")5556// Call CreateWitness with parameters matching the function signature:57// func (g *GrpcClient) CreateWitness(from, urlStr string) (*api.TransactionExtention, error)58tx, err := conn.CreateWitness(from, urlStr)5960if err != nil {61fmt.Printf("Error creating witness application transaction: %v\n", err)62return63}6465fmt.Println("Witness application transaction created successfully. Transaction details:")66jsonData, _ := json.MarshalIndent(tx, "", " ")67fmt.Println(string(jsonData))6869fmt.Println("\nBroadcasting transaction to the TRON network...")70result, err := conn.Broadcast(tx.Transaction)71if err != nil {72fmt.Printf("Error broadcasting transaction: %v\n", err)73return74}7576if !result.GetResult() {77fmt.Printf("Broadcast failed: %s\n", result.GetMessage())78return79}8081fmt.Println("Witness application successful! Result:")82resultJSON, _ := json.MarshalIndent(result, "", " ")83fmt.Println(string(resultJSON))84}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free