| 1 | import 'package:cw_evm/clients/evm_chain_client.dart'; |
| 2 | import 'package:flutter/foundation.dart'; |
| 3 | import 'package:web3dart/web3dart.dart'; |
| 4 | |
| 5 | class BSCClient extends EVMChainClient { |
| 6 | BSCClient() : super(chainId: 56); |
| 7 | |
| 8 | @override |
| 9 | Transaction createTransaction({ |
| 10 | required EthereumAddress from, |
| 11 | required EthereumAddress to, |
| 12 | required EtherAmount amount, |
| 13 | EtherAmount? maxPriorityFeePerGas, |
| 14 | Uint8List? data, |
| 15 | int? maxGas, |
| 16 | EtherAmount? gasPrice, |
| 17 | EtherAmount? maxFeePerGas, |
| 18 | int? nonce, |
| 19 | }) { |
| 20 | EtherAmount? finalGasPrice = gasPrice; |
| 21 | |
| 22 | if (gasPrice == null && maxFeePerGas != null) { |
| 23 | // If we have EIP-1559 parameters but no legacy gasPrice, then use maxFeePerGas as gasPrice |
| 24 | // BSC RPC nodes may have issues with EIP-1559 transaction encoding |
| 25 | finalGasPrice = maxFeePerGas; |
| 26 | } |
| 27 | |
| 28 | return Transaction( |
| 29 | from: from, |
| 30 | to: to, |
| 31 | value: amount, |
| 32 | data: data, |
| 33 | maxGas: maxGas, |
| 34 | gasPrice: finalGasPrice, |
| 35 | nonce: nonce, |
| 36 | // maxFeePerGas: maxFeePerGas, |
| 37 | // maxPriorityFeePerGas: maxPriorityFeePerGas, |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | @override |
| 42 | Uint8List prepareSignedTransactionForSending(Uint8List signedTransaction) => signedTransaction; |
| 43 | |
| 44 | @override |
| 45 | int get chainId => 56; |
| 46 | } |