moca_chains 1.4.2 moca_chains: ^1.4.2 copied to clipboard
Chains package for Moca App. This library gives the developer common methods for interacting with chains.
example/moca_chains_example.dart
import 'package:moca_chains/moca_chains.dart';
import 'package:moca_chains/src/chains/evm/erc20.dart';
import 'package:moca_chains/src/swaps/swap_types.dart';
String mnemonic = '';
void main() async {
final chain = ChainFactory('solana').build();
final privateHex = await chain.initMnemonic('YOUR_MNEMONIC');
final balance =
await chain.getBalance(chain.getKeysFromPrivateHex(privateHex).address);
print(balance);
}
void uniswap() async {
ERC20 chain = ChainFactory('usdc').build();
final privateHex = await chain.initMnemonic(mnemonic);
final keys = chain.getKeysFromPrivateHex(privateHex);
final swapper = await SwapFactory(SwapperType.uniswap);
final params = GetQuoteParams(
fromAsset: SupportedChains.usdc,
toAsset: SupportedChains.arb,
amount: double.parse((2 * 1e6).toString()),
destination: keys.address,
affiliateBasis: null,
sender: privateHex);
final SwapQuote quote = await swapper.quote(params);
// final paramsMake = MakeSwapParams(
// fromAsset: SupportedChains.usdc,
// toAsset: SupportedChains.arb,
// amount: (2 * 1e6),
// destination: keys.address,
// privateHex: privateHex,
// memo: null,
// inboundAddress: null
// );
// final SwapResponse res = await swapper.make(paramsMake);
print(quote.amountOut);
}