1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
// RpcGenTokenTransfer 生成token转账交易
func RpcGenTokenTransfer(ctx context.Context, tokenAddress string, opts *bind.TransactOpts, to string, balance int64) (*types.Transaction, error) {
address := common.HexToAddress(tokenAddress)
instance, err := NewEth(address, client)
if err != nil {
return nil, err
}
tx, err := instance.Transfer(opts, common.HexToAddress(to), big.NewInt(balance))
if err != nil {
return nil, err
}
return tx, nil
}
// 获取nonce值
nonce, err := GetNonce(dbTx, hotAddress)
if err != nil {
return err
}
rpcTx, err := ethclient.RpcGenTokenTransfer(
context.Background(),
tokenRow.TokenAddress,
&bind.TransactOpts{
Nonce: big.NewInt(nonce),
GasPrice: big.NewInt(gasPrice),
GasLimit: uint64(gasLimit),
},
withdrawRow.ToAddress,
tokenBalance,
)
if err != nil {
return nil
}
signedTx, err := types.SignTx(rpcTx, types.NewEIP155Signer(big.NewInt(chainID)), key)
if err != nil {
return err
}
ts := types.Transactions{signedTx}
rawTxBytes := ts.GetRlp(0)
rawTxHex := hex.EncodeToString(rawTxBytes)
txHash := strings.ToLower(signedTx.Hash().Hex())
|