5
5
"github.com/ethereum/go-ethereum"
6
6
"github.com/ethereum/go-ethereum/common"
7
7
"github.com/ranjbar-dev/ethereum-wallet/geth"
8
- "golang.org/x/crypto/sha3"
9
8
"math/big"
10
9
)
11
10
@@ -49,7 +48,7 @@ func estimateEthTransactionFee(node Node, toAddressHex string) (int64, error) {
49
48
return temp .Int64 (), nil
50
49
}
51
50
52
- func estimateErc20TransactionFee (node Node , toAddressHex string ) (int64 , error ) {
51
+ func estimateErc20TransactionFee (node Node ) (int64 , error ) {
53
52
54
53
client , err := geth .GetGETHClient (node .Http )
55
54
if err != nil {
@@ -72,44 +71,11 @@ func estimateErc20TransactionFee(node Node, toAddressHex string) (int64, error)
72
71
return 0 , err
73
72
}
74
73
75
- gasLimit , err := erc20GasLimit (node , toAddressHex )
76
- if err != nil {
77
- return 0 , err
78
- }
74
+ gasLimit := 70000
79
75
80
76
fee := new (big.Int ).SetInt64 (baseFee .Int64 () + gasTipCap .Int64 ())
81
77
82
78
temp := new (big.Int ).Mul (new (big.Int ).SetInt64 (int64 (gasLimit )), fee )
83
79
84
80
return temp .Int64 (), nil
85
81
}
86
-
87
- func erc20GasLimit (node Node , toAddressHex string ) (uint64 , error ) {
88
- toAddress := common .HexToAddress (toAddressHex )
89
-
90
- client , err := geth .GetGETHClient (node .Http )
91
- if err != nil {
92
- return 0 , err
93
- }
94
-
95
- transferFnSignature := []byte ("transfer(address,uint256)" )
96
- hash := sha3 .NewLegacyKeccak256 ()
97
- hash .Write (transferFnSignature )
98
- methodID := hash .Sum (nil )[:4 ]
99
-
100
- paddedAddress := common .LeftPadBytes (toAddress .Bytes (), 32 )
101
-
102
- amount := new (big.Int )
103
- amount .SetString ("1000000000000000000000000" , 10 ) // 1000 tokens
104
- paddedAmount := common .LeftPadBytes (amount .Bytes (), 32 )
105
-
106
- var data []byte
107
- data = append (data , methodID ... )
108
- data = append (data , paddedAddress ... )
109
- data = append (data , paddedAmount ... )
110
-
111
- return client .EstimateGas (context .Background (), ethereum.CallMsg {
112
- To : & toAddress ,
113
- Data : data ,
114
- })
115
- }
0 commit comments