NOTE: For this quickstart you MUST use NodeJS version > 21.7.3. If you use a previous version, you MUST install dotenv & crypto@1.0.1 (this lib is deprecated and built-in. Recommend: update node version).
DISCLAIMER: This guide is for using Bit2Me Broker, NOT Bit2Me PRO. For a how to use of Bit2Me PRO, please check this documentation and this repository.
TIP:
<>
is for required data,[]
is for optional data.
- Run
cp .env.example .env
in your terminal. - Change
API_KEY
andSECRET
in.env
file with yours. - Execute
npm i
.
- To get all available currencies in Bit2Me, with available actions, its networks and withdrawal fees, execute
npm run list-currencies
. This script retrieves all currencies information and may take some time.- We strongly recommend that you store the output in a file:
npm run --silent list-currencies > currencies.json
.
- We strongly recommend that you store the output in a file:
- To get currencies quotes, execute
npm run market-quotes [currency]
. Ifcurrency
is empty, will return market currencies quotes in EUR. - To get market information of a currency, execute
npm run market-data <currency>
.
- To create a subaccount:
- Change
body
values in./createSubaccount.js
file. - Execute
npm run create-subaccount
.- Successful response example:
{ userId: subaccount-id }
.
- Successful response example:
- Change
- To set an alias, execute
npm run set-alias <alias> [subaccount-id]
. Ifsubaccount-id
is empty, alias will be set to main account. - To list subaccounts, execute
npm run list-subaccounts
. - To read an account, execute
npm run read-account [subaccount-id]
. Ifsubaccount-id
is empty, will return the main account data.
KYC process is currently outside the scope of this tool. Please feel free to reach out or complete the process through the Bit2Me UI.
- To create pocket, execute
npm run create-pocket <currency> <name> [subaccount-id]
. Ifsubaccount-id
is empty,currency
pocket will be created for main account. - To list pockets, execute
npm run list-pockets [currency] [subaccount-id]
. Ifsubaccount-id
is empty, pockets list from main account will be returned. Ifcurrency
is empty, will return the whole list of your pockets. - To get your balance, execute
npm run balance [currency] [subaccount-id]
. Ifsubaccount-id
is empty, balance from main account will be returned. Ifcurrency
is empty, will return the whole balance from your account.
- To deposit EUR, execute
npm run deposit-eur [subaccount-id]
. Ifsubaccount-id
is empty, the bank accounts of the main account will be displayed, and any EUR deposits will be credited to the main account.
- To deposit crypto, execute
npm run deposit-crypto <crypto> <network> [subaccount-id]
. Ifsubaccount-id
is empty, will return main account addresses.
- To get a transaction, execute
npm run read-tx <tx-id> [subaccount-id]
. Ifsubaccount-id
is empty,tx-id
will be searched in main account transaction list. - To get your transaction list, execute
npm run list-tx [subaccount-id]
. Ifsubaccount-id
is empty, will be returned the transaction list of main account.
- To buy crypto, execute
npm run buy <amount> < - | EUR > <crypto> [subaccount-id]
. Ifsubaccount-id
is empty, an attempt will be made to buy for the main account. If you want to know all the availablecrypto
, you can executenpm run list-currencies
.- You can buy
<amount> <crypto>
or<amount> EUR <crypto>
. Examples:- I want to buy 0.01 ETH ➙
npm run buy 0.01 - ETH [subaccount-id]
. - I want to buy 5 EUR in ETH ➙
npm run buy 5 EUR ETH [subaccount-id]
.
- I want to buy 0.01 ETH ➙
- You can buy
- To swap crypto for another crypto, execute
npm run swap <amount> <crypto-origin> <crypto-destination> [subaccount-id]
. Ifsubaccount-id
is empty, an attempt will be made to swapcrypto-origin ➙ crypto-destination
for the main account. If you want to know all the availablecrypto
, you can executenpm run list-currencies
.- Examples:
- I want to swap 0.01 ETH to BTC ➙
npm run swap 0.01 ETH BTC [subaccount-id]
.
- I want to swap 0.01 ETH to BTC ➙
- Examples:
- To sell crypto, execute
npm run sell <amount> <crypto> [subaccount-id]
. Ifsubaccount-id
is empty, an attempt will be made to sell crypto for the main account.- Examples:
- I want to sell 0.01 ETH ➙
npm run sell 0.01 ETH [subaccount-id]
.
- I want to sell 0.01 ETH ➙
- Examples:
If you want to configure 2FA in main account you MUST use Bit2Me UI.
2FA is needed for ANY WITHDRAW operation
-
To get TOTP code, execute
npm run get-totp <subaccount-id>
. After that, configuresecret
in your auth app to generate valid 2FA codes.{ secret: secret-id }
-
To finish TOTP configuration, execute
npm use set-2fa <subaccount-id> <TOTP>
.- Response example:
{ result: true | false }
- Response example:
- To withdraw crypto, execute
npm run wd-crypto <amount> <crypto> <network> <address> <TOTP> [subaccount-id]
. Ifsubaccount-id
is empty, withdraw operation will be executed in main account.
- To withdraw fiat to a bank account, execute
npm run wd-fiat <amount> <TOTP> [subaccount-id]
. Due to console writing lack of security, you need to changebody
in./withdrawFiat.js
. Ifsubaccount-id
is empty, fiat withdraw operation will be executed for main account.
- To make a transfer between accounts, execute
npm run pay <amount> <crypto> <alice> <bob> <alice-TOTP>
.alice
andbob
are accounts, you MUST fill this params with an uuid. In order to make a social-pay,bob
MUST have an alias already set. If not, please executenpm run set-alias <alias> <bob>
.- Example: Alice wants to transfer Bob 0.01 ETH ➙
npm run pay 0.01 ETH 9fb38ddd-3b09-4823-9a2e-668e9bc96964 4512ec8e-f269-4b62-aeea-c64041865b83 451450
.
- Example: Alice wants to transfer Bob 0.01 ETH ➙
The authentication between Bit2Me and you can also work with the RFC-7519 standard, popularly known as JSON Web Token (JWT). This means, that if you do not want the actions of your subaccounts to depend exclusively on a backend, you can have them authenticated with a JWT. The management of this token is up to you.
- To get a valid JWT, execute
npm run jwt [subaccount-id]
. Ifsubaccount-id
is empty, a JWT associated with your main account will be returned.
- A backend retrieves a valid JWT for an account.
- Store this JWT in FE (using localStorage or similar).
- You can make requests without needing the API Key + Secret auth method, using this header directly from the client:
headers: {
Authorization: `Bearer ${jwt}`
}
As long as the exp
of the token is <=
than now
, it will work.
Happy hacking!