🐇Wallet providers - Request an order
How to create an order for wallet providers
When working with wallet providers like MetaMask, you need to handle the connection and signing process differently. Here are examples for integrating with MetaMask and other wallet providers.
EVM Chains
const order = await Order.create({
user: userAddress,
sourceChainId: ChainID.Arbitrum,
sourceTokenAddress: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', // USDT
sourceTokenAmount: BigInt(10_000_000), // 10 USDT
destinationChainId: ChainID.Solana,
destinationTokenAddress: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
destinationTokenMinAmount: BigInt(9_500_000),
destinationAddress: '3Kiz4oBXpR9YuPNsVfvE5XnNzgwjrM9m2CbRzyyEVkpQ',
minStablecoinAmount: BigInt(9_800_000),
deadline: Math.floor(Date.now() / 1000) + 3600,
});
// Sign the order with MetaMask
const { orderTypedData, nonce } = await getEvmOrderTypedData(order); // You'll need to implement this
// Prompt the user to sign typed data using your wallet provider (wagmi, etc...)
const signature = await signer.signTypedData( // '0x...'
orderTypedData.domain,
orderTypedData.types,
orderTypedData.message
);
// Once generated the signature by the wallet provider
let response = await sendEvmRequest({ order, signature, nonce });
Solana
const solanaOrder = await Order.create({
user: userAddress,
sourceChainId: ChainID.Solana,
sourceTokenAddress: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
sourceTokenAmount: BigInt(10_000_000),
destinationChainId: ChainID.Solana,
destinationTokenAddress: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
destinationTokenMinAmount: BigInt(9_500_000),
destinationAddress: '3Kiz4oBXpR9YuPNsVfvE5XnNzgwjrM9m2CbRzyyEVkpQ',
minStablecoinAmount: BigInt(9_800_000),
deadline: Math.floor(Date.now() / 1000) + 3600,
});
// Sign the order with Solana wallet
const { orderKeyPair, instructions } = await getSolanaOrderInstructions(solanaOrder); // You'll need to implement this
// Prompt the user to send this tx with the wallet provider (Phantom, MetaMask)
const tx = await signAndSendTransaction(
[signerKeyPair, orderKeyPair.keyPair],
compiledInstructionsTransaction
);
// Once the tx is sent to blockchain, call sendSolanaRequest
let solanaResponse = await sendSolanaRequest({ order: solanaOrder, orderPubKey });
Sui
const suiOrder = await Order.create({
user: userAddress,
sourceChainId: ChainID.Sui,
sourceTokenAddress: '0xf16e6b723f242ec745dfd7634ad072c42d5c1d9ac9d62a39c381303eaa57693a',
sourceTokenAmount: BigInt(10_000_000),
destinationChainId: ChainID.Solana,
destinationTokenAddress: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
destinationTokenMinAmount: BigInt(9_500_000),
destinationAddress: '3Kiz4oBXpR9YuPNsVfvE5XnNzgwjrM9m2CbRzyyEVkpQ',
minStablecoinAmount: BigInt(9_800_000),
deadline: Math.floor(Date.now() / 1000) + 3600,
});
const transaction = await getSuiOrderTransaction(suiOrder);
// Prompt the user to send that transaction to SUI blockchain
const suiTx = await client.signAndExecuteTransaction({
signer,
transaction,
});
// Once the tx is sent to blockchain, call sendSuiRequest
let suiResponse = await sendSuiRequest({ order: suiOrder, transactionDigest: suiTx.digest });
Last updated