moca_chains 1.6.0 moca_chains: ^1.6.0 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';
String mnemonic = '';
void main() async {
ChainFactory.initialize('maya');
Chain outbound = ChainFactory.instance.build();
String outboundHex = await outbound.initMnemonic(mnemonic);
outbound.getKeysFromPrivateHex(outboundHex).address;
ChainFactory.initialize('kujira');
Chain inbound = ChainFactory.instance.build();
String hex = await inbound.initMnemonic(mnemonic);
final inboundAddress = inbound.getKeysFromPrivateHex(hex).address;
print(inboundAddress);
}
void uniswap() async {
ChainFactory.initialize('usdc');
ERC20 chain = ChainFactory.instance.build();
final privateHex = await chain.initMnemonic(mnemonic);
final keys = chain.getKeysFromPrivateHex(privateHex);
final swapper = await SwapFactory(SwapperType.uniswap, 'moca');
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);
}