Skip to main content

Contract API

Reference guide for the BitEscrow Contract API.

EndpointDescription
/api/contract/createPublish a new contract.
/api/contract/listList contracts by pubkey.
/api/contract/:cidRead a contract via ID.
/api/contract/:cid/cancelCancel a contract.
/api/contract/:cid/fundsList funds in a contract.

Notice any mistakes, or something missing? Please let us know!
You can submit an issue here: Submit Issue


Create a Contract

Create a new contract on the escrow server.

Request Format

method   : 'POST'
endpoint : '/api/contract/create'
headers : { 'content-type' : 'application/json' }
body : JSON.stringify(contract_request)

Request Body

interface ContractPublishRequest {
endorsements ?: string[] // Optional endorsements of proposal.
proposal : ProposalData // Completed proposal document.
}

Response Interface

interface ContractDataResponse {
data : {
contract : ContractData
}
}

Example Request

// Define the script engine to use.
const engine = CVM
// Define a proposal and optional endorsements.
const req = { endorsements, proposal }
// Deliver the publish request to the server.
const res = await client.contract.create(req, engine)
// Check if response is valid.
if (!res.ok) throw new Error(res.error)
// Unpack our published contract.
const { contract } = res.data

See the full code example here.

Example Response

Related Interfaces


List Contracts By Pubkey

Request a list of contracts that are endorsed by the token's pubkey.

Request Format

method   : 'GET'
endpoint : '/api/contract/list'
headers : { 'Authorization' : 'Token ' + auth_token }

Response Interface

interface ContractListResponse {
data : {
contracts : ContractData[]
}
}

Example Request

// Generate a request token.
const req = signer.contract.list()
// Submit the request and token.
const res = await client.contract.list(req)
// Check the response is valid.
if (!res.ok) throw new Error(res.error)
// Unpack our data payload.
const { contracts } = res.data

See the full code example here.

Related Interfaces


Read a Contract By Id

Fetch a contract from the server by its identifier (cid).

Request Format

method   : 'GET'
endpoint : '/api/contract/:cid'

Response Interface

interface ContractDataResponse {
data : {
contract : ContractData
}
}

Example Request

// Fetch a contract from the server.
const res = await client.contract.read(cid)
// Check the response is valid.
if (!res.ok) throw new Error(res.error)
// Unpack the data object.
const { contract } = res.data

See the full code example here.

Example Response

Related Interfaces


Cancel a Contract

Request to cancel a contract (must be the moderator).

Request Format

method   : 'GET'
endpoint : '/api/contract/:cid/cancel'
headers : { 'Authorization' : 'Token ' + auth_token }

Response Interface

interface ContractDataResponse {
data : {
contract : ContractData
}
}

Example Code

// Generate an auth token from the moderator's signer.
const req = signer.contract.cancel(cid)
// Send the cancel request, along with the auth token.
const res = await client.contract.cancel(cid, req)
// If the request fails, throw an error.
if (!res.ok) throw new Error(res.error)
// Unpack the response data.
const { contract } = res.data

See the full code example here.

Example Response

Related Interfaces:


List Funding By Id

Fetch a list of funds locked to a contract.

Request Format

method   : 'GET'
endpoint : '/api/contract/:cid/funds'

Response Interface

interface FundListResponse {
data : {
funds : FundingData[]
}
}

Example Request

// Fetch a contract from the server by cid.
const res = await client.contract.funds(cid)
// Check the response is valid.
if (!res.ok) throw new Error(res.error)
// Unpack the data object.
const { funds } = res.data

See the full code example here.

Related Interfaces