moca_chains 1.4.7 moca_chains: ^1.4.7 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 {
Chain outbound = ChainFactory("maya").build();
String outboundHex = await outbound.initMnemonic(mnemonic);
outbound.getKeysFromPrivateHex(outboundHex).address;
Chain inbound = ChainFactory("kujira").build();
String hex = await inbound.initMnemonic(mnemonic);
final inboundAddress = inbound.getKeysFromPrivateHex(hex).address;
print(inboundAddress);
}
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.usdc,
amount: double.parse((2 * 1e6).toString()),
destination: keys.address,
affiliateBasis: null,
sender: keys.address);
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);
print(res.inboundTxHash);
}