Skip to content

Example: Deposit

Deposit

Send the deposit transaction to the Gateway contract.

client.ts
import { parseTransactionRequestForViem } from '@silentswap/sdk';
 
// parse transaction request from API response
const txRequestParams = parseTransactionRequestForViem(orderResponse.transaction);
 
// send transaction
const hash = await client.sendTransaction(txRequestParams);
console.log(`Transaction sent: ${hash}`);
 
// wait for transaction to be mined
const txReceipt = await client.waitForTransactionReceipt({ hash });
console.log(`Deposit of ${BigNumber(orderResponse.response.order.deposit).shiftedBy(-6).toFixed()} USDC to SilentSwap Gateway contract confirmed at: ${txReceipt.transactionHash}`);

Watch for finalization

Watch for an ERC-20 token transfer to the recipient's address to verify the completion of the order. The transfer will come from the facilitator account for coin type 60 (ETH) at the first output index (0).

client.ts
// start waiting for funds to arrive on destination
const destinationClient = createWalletClient({
    chain: mainnet,
    transport: http(),
}).extend(publicActions);
 
destinationClient.watchContractEvent({
    address: tokenAddr,
    abi: erc20Abi,
    eventName: 'Transfer',
    args: {
        to: recipientAddr,
        from: facilitator0EthEvm.address,
    },
    onLogs: (logs) => {
        for (const log of logs) {
            const { to, value } = log.args;
 
            console.log(`Recipient ${to} received ${BigNumber(value!).shiftedBy(-tokenDecimals).toFixed()} ${tokenSymbol}`);
        }
    },
});