Smart Contract API
This document describes how to interact with Orderly’s smart contract methods

Introduction

Smart contract frontend integration builds are based on the Near API JS library. Please review the Overview section to learn about action flows.
Orderly has two main contracts deployed that users will interact with:
asset-manager.orderly.testnet
ft-faucet-usdc.orderly.testnet

Contract Addresses (Testnet)

Asset Manager asset-manager.orderly.testnet
USDC Faucet ft-faucet-usdc.orderly.testnet

Smart Contract Methods

Refer to this guide on how to use the listed methods.
Use NEAR API JS library to interact with the smart contract methods or the following format if using the CLI:
near call $CONTRACT function_name '{"parameter": "YOUR ACCOUNT_ID"}'

Authentication/Registration

All our interfaces require two keys to access, Orderly Key Pair (ed25519) and Trading Key Pair (secp256k1). Orderly Access Key Pair is generated by the wallet and more information can be found here and instructions on how to create the keys can be found here. Trading keys should be generated by the front-end.

Asset Manager Methods

For first-time users, the following method is called to create an account:
get
create_user_account
Registers an account in the smart contract
If an account already exists, the following method will connect Orderly Access keys to the smart contract:
get
user_announce_key
Binds Orderly Access Keys to the smart contract
After Orderly Access keys are generated and submitted to the smart contract, the trading keys should be generated using elliptic-curve cryptography, which can be found here, stored in the local storage, and then sent to the smart contract using the following method:
get
user_request_set_trading_key
Creates and binds user’s trading key to user_id

Deposit

There are two ways to deposit tokens into a wallet, depending on the token type. NEAR is the only native token and all the other tokens are fungible tokens.

Asset Manager Methods

In order to deposit NEAR into an asset manager contract, call the following method:
get
user_deposit_native_token
Deposits NEAR into a wallet

Fungible Token Methods

In order to deposit any other token, known as fungible tokens, use the following method which will transfer tokens from a wallet into a smart contract.
get
ft_transfer_call
Transfers tokens from a wallet to the smart contract
It generates the response from NEAR sdk in the following format:
near_sdk::Promise

Withdrawal

If a user wishes to withdraw funds from the asset manager into their wallet, call the following method:
get
user_request_withdraw
Requests for token withdrawal

Data Access

Asset Manager Methods

get
is_token_listed
Checks if a token is supported by Orderly
To retrieve a list of whitelisted tokens supported by Orderly use the following method. This can also be retrieved through Off-Chain APIs described in the next section.
get
get_listed_tokens
Gets a token whitelist
This generates the Vec<AccountId>response of borsh format, a binary serialization protocol. More details can be found here.
The following method queries user account existence on the contract:
get
user_account_exists
Checks if user account exists
get
is_symbol_listed
Checks if a trading pair is listed
To retrieve your trading key use the following function:
get
get_user_trading_key
Returns a trading key of the user
This generates the response of type Option<Base64VecU8>
// Example of return value
// if options is_some
'MDNmYTI0ZTBjYWUxNDJkZDY3ZDdjYzhmNjQ3OGNjOTdmNTcyZjlmOTgxMzlmODM5NjQ2NTlmNzBmMDI2Y2Y0MA=='
// if option is_none
null
This guide is a WIP. If you have any suggestions or questions please contact us by email
Copy link
On this page
Introduction
Contract Addresses (Testnet)
Smart Contract Methods
Authentication/Registration
get
Registers an account in the smart contract
get
Binds Orderly Access Keys to the smart contract
get
Creates and binds user’s trading key to user_id
Deposit
get
Deposits NEAR into a wallet
get
Transfers tokens from a wallet to the smart contract
Withdrawal
get
Requests for token withdrawal
Data Access
get
Checks if a token is supported by Orderly
get
Gets a token whitelist
get
Checks if user account exists
get
Checks if a trading pair is listed
get
Returns a trading key of the user