Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to achieve TRC20 transfer #117

Open
wangrizhao opened this issue Dec 11, 2023 · 3 comments
Open

How to achieve TRC20 transfer #117

wangrizhao opened this issue Dec 11, 2023 · 3 comments

Comments

@wangrizhao
Copy link

No description provided.

@chernyshev
Copy link

   fromAddress := "..."
   toAddress := "..."
   contractAddress := "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" // Tether USDT contract address
   amount := big.NewInt(1000000)                           // 1 USDT
   feeLimit := int64(1000000000)

   tx, err = s.client.TRC20Send(fromAddress, toAddress, contractAddress, amount, feeLimit)
   fmt.Println(tx)

@blackcats1999
Copy link

tronClient.Broadcast(userSignedTx) sends a transaction and gets a receipt {"result":true}, which confirms that the transaction is successful, but does not get the correct transaction hash. Is this normal?

@69tc
Copy link

69tc commented Dec 19, 2024

`
rawData, err := proto.Marshal(tx.Transaction.GetRawData())
if err != nil {
return "", errors.Wrap(err, "proto.Marshal")
}
h256h := sha256.New()
h256h.Write(rawData)
hash := h256h.Sum(nil)

privateKeyBytes, _ := hex.DecodeString(senderPrivKey)
sk, _ := btcec.PrivKeyFromBytes(privateKeyBytes)

signature, err := crypto.Sign(hash, sk.ToECDSA())
if err != nil {
	return "", errors.Wrap(err, "crypto.Sign")
}
txInfo.Transaction.Signature = append(tx.Transaction.Signature, signature)

result, err := e.RpcClient.Broadcast(tx.Transaction)

if err != nil {
	return "", errors.Wrap(err, "e.RpcClient.Broadcast")
}
if result == nil {
	return "", errors.New("e.RpcClient.Broadcast result nil")
}

return strings.TrimLeft(common.BytesToHexString(txInfo.GetTxid()), "0x"), nil`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants