Brine's Docupaper
AboutTrade
  • ABOUT
    • πŸ“’Brine Docupaper
    • πŸͺ™Tokenomics
  • πŸ—žοΈBrine Bytes
    • 🧡October Edition
  • TECH
    • πŸ‘©β€πŸ’»Tech Docupaper
      • 🏨High level architecture
      • πŸ€”Starkware logic
      • 🌊Transactional flow
        • Off-chain accounts
        • The deposit flow
        • The withdrawal flow
        • The trade flow
        • The transfer flow
        • Full withdrawal
    • πŸ”ŒAPI Documentation
      • πŸ˜‹Getting started
        • Test connectivity
      • πŸ“ˆMarket
        • 24hr Tickers Price
        • K-line/Candlestick data
        • Orderbook
        • Recent trades
      • ↔️Trading
        • Create order
        • Get order
        • List orders
        • Cancel order
        • List trades
      • πŸ”Account
        • Login
        • Profile Information
        • Balance details
        • Profit and loss details
      • 🌏Web-socket stream
        • πŸ—οΈPrivate web-socket connection
        • πŸ‘₯Public websocket connection
      • ✨Internal Transfer
        • Create Internal Transfer
        • Get Internal Transfer
        • Check User Existence
        • List Internal Transfers
      • πŸ§ͺSDK Reference
        • NodeJS SDK
  • FOR USERS
    • πŸ“’User Docuguide
      • πŸ’»Web App
        • Sign up through Metamask
        • Sign up through Wallet Connect
        • Place a Market Order Trade
        • Place a Limit Order Trade
        • Refer Brine to a Friend
        • Deposit with Metamask
        • Withdraw to Metamask
  • LEGAL
    • ‼️Disclaimer
Powered by GitBook
On this page
  • 1. Initiate Internal Transfer
  • 2. Sign the msg_hash with the L2 key pair
  • 3. Process Internal Transfer

Was this helpful?

  1. TECH
  2. API Documentation
  3. Internal Transfer

Create Internal Transfer

PreviousInternal TransferNextGet Internal Transfer

Last updated 1 year ago

Was this helpful?

To create an internal transfer, first obtain the msg hash from the initiate endpoint /initiate/. Next, sign msgHash with your L2 key using the function. Finally, provide the signed message along with other required information to the process transfer API /process/.

Note: You will need to include the JWT Auth token to request headers to access this endpoint. To get the JWT Auth Token, refer the section of this document.

1. Initiate Internal Transfer

Before creating a new Internal Transfer, you will be required to obtain a msg hash by making use of this endpoint. Please note that this is a Private πŸ”’ route which means it needs to be authorized by the account initiating this request.

Endpoint

POST /sapi/v1/internal_transfers/v2/initiate/

Request Headers

{
  "Authorization": "JWT ***"
}

Request Body

Parameter
Type
Required
Description

organization_key

string

Yes

api_key

string

Yes

client_reference_id

string

No

This is an optional field. If not specified, then it’s generated randomly. You can use this to uniquely identify a transfer at your end.

currency

string

Yes

The currency of the transfer (e.g., USDC). Currently, we support USDC.

amount

decimal

Yes

The amount of the transfer

destination_address

string

Yes

The receiver's eth address.

Response

{
  "status": "success",
  "message": "Please sign the message, to complete the transaction",
  "payload": {
    "msg_hash": "0x1234567890abcdef",
    "nonce": 123456
  }
}

2. Sign the msg_hash with the L2 key pair

import { generateKeyPairFromEthPrivateKey } from '@brine-fi/brine-connector'

const keypair = generateKeyPairFromEthPrivateKey(
    ethPrivateKey, 
    'testnet' // The default value is "mainnet," and the allowed values are ['testnet', 'mainnet'].
) 

2.2 Use the L2 key pair to sign the msg_hash obtained from the initiate endpoint.

import { signInternalTxMsgHash } from '@brine-fi/brine-connector'

 const signature = signInternalTxMsgHash(
      keyPair,
      initiateResponse.payload.msg_hash,
 )

3. Process Internal Transfer

Process an internal transfer between two users. Before processing the transfer, you will be required to obtain a signature by using the initiate endpoint and the signing utils. Please note that this is a private πŸ”’ route, which means it needs to be authorized by the account initiating this request.

Endpoint

POST /sapi/v1/internal_transfers/v2/process/

Request Headers

{
  "Authorization": "JWT ***"
}

Request Body

Parameter
Type
Required
Description

organization_key

string

Yes

api_key

string

Yes

signature

JSON object with β€œr” and β€œs” keys

Yes

The signature of the transfer (obtained from the above sign endpoint)

nonce

integer

Yes

The nonce of the transfer (obtained from the above signInternalTxMsgHash function)

msg_hash

string

Yes

The message hash of the transfer (obtained from the above Initiate endpoint)

Response

{
    "status": "success",
    "message": "Internal transfer processed successfully",
    "payload": {
        "client_reference_id": "795278363509343",
        "amount": "1",
        "currency": "usdc",
        "from_address": "0x1234",
        "destination_address": "0x1234",
        "status": "success",
        "created_at": "2023-07-12T04:42:22.639933Z",
        "updated_at": "2023-07-12T04:43:37.373071Z"
    }
}

Reach out to Brine () to get the organization key and API key.

Reach out to Brine () to get the organization key and API key.

To sign the msg_hash obtained from the above endpoint, you need to generate the L2 key pair. Use the to generate the L2 key pair from your Ethereum private key. 2.1 Generating a L2 key pair from an ethereum private key

Reach out to Brine () to get the organization key and API key.

Reach out to Brine () to get the organization key and API key.

πŸ”Œ
✨
signInternalTxMsgHash
login
Nodejs-sdk
support@brine.fi
support@brine.fi
support@brine.fi
support@brine.fi