Quickstart
This page swaps 1 NEAR for USDT on Intear DEX and withdraws the USDT to your wallet, one contract call at a time, starting from an account that has never used Intear DEX. Every call goes to dex.intear.near. Arguments are JSON, amounts are integer strings in the asset’s smallest unit (yoctoNEAR for NEAR, so 1 NEAR is "1000000000000000000000000").
Before you start
Section titled “Before you start”The examples in these docs use near CLI and jq. Install near CLI, and import the account you’ll sign with:
npm install -g near-cli-rsnear account import-accountReplace alice.near in the examples with your account. The examples sign with sign-with-keychain, which uses the key that import-account saved.
1. Pay for storage
Section titled “1. Pay for storage”Your balances take storage in the engine contract, and you pay for it. Call storage_deposit with at least 0.005 NEAR attached:
near contract call-function as-transaction dex.intear.near storage_deposit \ json-args '{}' \ prepaid-gas '30.0 Tgas' attached-deposit '0.01 NEAR' \ sign-as alice.near network-config mainnet sign-with-keychain sendYou only do this once. You can top it up later or withdraw what you don’t use. See Storage.
2. Register the assets
Section titled “2. Register the assets”An account can only hold assets that are registered for it. Register both sides of the swap, with 1 yoctoNEAR attached:
near contract call-function as-transaction dex.intear.near register_assets \ json-args '{"asset_ids": ["near", "nep141:usdt.tether-token.near"]}' \ prepaid-gas '30.0 Tgas' attached-deposit '1 yoctoNEAR' \ sign-as alice.near network-config mainnet sign-with-keychain sendRegistering an asset that’s already registered does nothing, so it’s safe to always include it.
3. Deposit NEAR
Section titled “3. Deposit NEAR”Call deposit_near with the NEAR you want in your inner balance attached:
near contract call-function as-transaction dex.intear.near deposit_near \ json-args '{}' \ prepaid-gas '30.0 Tgas' attached-deposit '1 NEAR' \ sign-as alice.near network-config mainnet sign-with-keychain sendFor a NEP-141 token, call ft_transfer_call on the token contract instead. See Inner balances.
Check the balance with the asset_balance_of view method:
near contract call-function as-read-only dex.intear.near asset_balance_of \ json-args '{"of": {"Account": "alice.near"}, "asset_id": "near"}' \ network-config mainnet nowIt returns "1000000000000000000000000", or null if the asset isn’t registered.
4. Simulate the swap
Section titled “4. Simulate the swap”simulate_swap_simple is a view method that runs the swap without changing anything, and returns [amount_in, amount_out]. Use its amount_out to set the least you accept:
AMOUNT_OUT=$(near contract call-function as-read-only dex.intear.near simulate_swap_simple \ json-args '{ "dex_id": "slimedragon.near/xyk", "message": "AQAAAEBCDwABAAAA3QAAAAA=", "trader": "alice.near", "asset_in": "near", "asset_out": "nep141:usdt.tether-token.near", "amount": {"ExactIn": "1000000000000000000000000"} }' \ network-config mainnet now | jq -r '.[1]')# Accept up to 1% less than the simulationMIN_AMOUNT_OUT=$((AMOUNT_OUT * 99 / 100))message is passed to the DEX as is, and each DEX decides what goes there. For Plach (slimedragon.near/xyk), it’s the route in Borsh: AQAAAEBCDwABAAAA3QAAAAA= swaps the whole amount through pool 221, NEAR/USDT.
5. Swap
Section titled “5. Swap”Call swap_simple with the same arguments, without trader (it’s you), and with a constraint: the minimum amount you accept for an exact input, or the maximum amount you pay for an exact output. Attach 1 yoctoNEAR:
near contract call-function as-transaction dex.intear.near swap_simple \ json-args "$(jq -n --arg min_amount_out "$MIN_AMOUNT_OUT" '{ "dex_id": "slimedragon.near/xyk", "message": "AQAAAEBCDwABAAAA3QAAAAA=", "asset_in": "near", "asset_out": "nep141:usdt.tether-token.near", "amount": {"ExactIn": "1000000000000000000000000"}, "constraint": $min_amount_out }')" \ prepaid-gas '100.0 Tgas' attached-deposit '1 yoctoNEAR' \ sign-as alice.near network-config mainnet sign-with-keychain sendIt returns [amount_in, amount_out]. If the output is lower than constraint, the call fails and nothing changes. See Swaps.
6. Withdraw
Section titled “6. Withdraw”Your wallet must be registered on the token contract (have a storage deposit there) to receive USDT. Skip this if you already hold USDT:
near contract call-function as-transaction usdt.tether-token.near storage_deposit \ json-args '{"account_id": "alice.near", "registration_only": true}' \ prepaid-gas '30.0 Tgas' attached-deposit '0.00125 NEAR' \ sign-as alice.near network-config mainnet sign-with-keychain sendThen send the USDT from your inner balance to your wallet with withdraw, 1 yoctoNEAR attached:
near contract call-function as-transaction dex.intear.near withdraw \ json-args '{ "asset_id": "nep141:usdt.tether-token.near", "amount": {"Full": {"at_least": null}} }' \ prepaid-gas '50.0 Tgas' attached-deposit '1 yoctoNEAR' \ sign-as alice.near network-config mainnet sign-with-keychain sendFull withdraws the whole balance. Use {"Exact": "..."} for a specific amount. If the transfer fails, the tokens go back to your inner balance.
In one transaction
Section titled “In one transaction”Steps 3 to 6 can be one call, and with a NEP-141 token as input, the deposit can be part of it too: ft_transfer_call with a list of operations in msg deposits, swaps and withdraws in one transaction.