Skip to content

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").

The examples in these docs use near CLI and jq. Install near CLI, and import the account you’ll sign with:

Terminal window
npm install -g near-cli-rs
near account import-account

Replace alice.near in the examples with your account. The examples sign with sign-with-keychain, which uses the key that import-account saved.

Your balances take storage in the engine contract, and you pay for it. Call storage_deposit with at least 0.005 NEAR attached:

Terminal window
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 send

You only do this once. You can top it up later or withdraw what you don’t use. See Storage.

An account can only hold assets that are registered for it. Register both sides of the swap, with 1 yoctoNEAR attached:

Terminal window
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 send

Registering an asset that’s already registered does nothing, so it’s safe to always include it.

Call deposit_near with the NEAR you want in your inner balance attached:

Terminal window
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 send

For 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:

Terminal window
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 now

It returns "1000000000000000000000000", or null if the asset isn’t registered.

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:

Terminal window
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 simulation
MIN_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.

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:

Terminal window
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 send

It returns [amount_in, amount_out]. If the output is lower than constraint, the call fails and nothing changes. See Swaps.

Your wallet must be registered on the token contract (have a storage deposit there) to receive USDT. Skip this if you already hold USDT:

Terminal window
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 send

Then send the USDT from your inner balance to your wallet with withdraw, 1 yoctoNEAR attached:

Terminal window
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 send

Full withdraws the whole balance. Use {"Exact": "..."} for a specific amount. If the transfer fails, the tokens go back to your inner balance.

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.