42 lines
923 B
Go
42 lines
923 B
Go
package tron
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/fbsobreira/gotron-sdk/pkg/client"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
)
|
|
|
|
|
|
func (ta *TronAccount) ApproveUSDTSpender(spender string, amount string) (string, error) {
|
|
amountFloat, _ := strconv.ParseFloat(amount, 64)
|
|
holder := ta.Address()
|
|
conn := client.NewGrpcClient(tronNode.grpcNode)
|
|
err := conn.Start(grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
txe, err := conn.TRC20Approve(holder, spender, tronNode.contractAddress, Float64ToDecimals(amountFloat, 6), tronNode.feeLimit)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
tx, err := ta.SignTx(txe.Transaction)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
_, err = conn.Broadcast(tx)
|
|
if err != nil {
|
|
fmt.Println("Broadcast error: ", err)
|
|
return "", err
|
|
}
|
|
|
|
conn.Stop()
|
|
return hex.EncodeToString(txe.GetTxid()), nil
|
|
|
|
} |