import{EscrowClient}from'@cmdcode/escrow-api'// Create a secret key.constsecret=Buff.str('alice').digest// Create a client object using a secret key.constclient=newEscrowAPI(secret)// You can view the pubkey and access the API tools directly.const{API, pubkey }=client// You can fetch a contract by Id.constcontract=awaitclient.getContract(contract_id)
Create a contract
import{EscrowContract}from'@cmdcode/escrow-api'// Create a contract using a client and template.constcontract=awaitEscrowContract.create(client,{title : 'Example Escrow Contract'})
// Main ContractData object.interfaceContractData{contract_id : stringmembers : string[]status : "draft"|"published"|"active"|"disputed"|"closed"revision : numbercreated_at : Dateupdated_at : Dateclaims: ClaimData[]{
data : string[]
methods : string[]
params : string[]
value : number}
data: {}
details: {// Contract info is editable by the admin.
updated_at : Date
title : string
admin : string
agent : string
depositor : string
desc ?: string|undefined
terms ?: string|undefined}endorsements : EndorseData[]{// Collect signed endorsements from other members.updated_at : Datepubkey : string
hash : string
signature : string}fees: PaymentData[]{address : string
note ?: string
value : number}meta: {// Metadata is updated by the server.block_id : string
open_txid ?: string|undefinedclose_txid ?: string |undefined}payments: PaymentData[]{address : string
note ?: string
value : number}room: {// This data is for collaboration and signing.secret : string
nonce ?: string|undefinedpubkey ?: string |undefinedhash ?: string |undefined}profiles: {// Each member manages their own profile data.updated_at : Datepubkey : string
nonce : string
alias : string}[]records: {// All members can manage records for the contract.updated_at : Datepubkey : string
label : string
kind : "data"|"script"|"term"content : string[]}[]signatures: {updated_at : Datekind : "claim"|"settle"outputs : string[]pubkey : string
sighash : string
txhex : string
psig : string}[]transactions: string[]}interfacePaymentData{address : string
note ?: string
value : number}interfaceCoinLock{method : stringparams : string[]version : string}
EscrowContract API Reference
constcontract=newEscrowContract(client,contract_id)letcontract={cid : string,API : ContractRouter,pubkey : string,// Claim outputs show pending closing tx.claims : Promise<ClaimData[]>,// Deposit inputs are used in the closing tx.deposits : Promise<DepositData[]>,details : Promise<ContractDetails>,endorsements : Promise<EndorseData[]>,// Fee outputs are used in the closing tx.fees : Promise<FeeData[]>,members : Promise<Map<string,ProfileData>>,meta : Promise<ContractMeta>,// Payment outputs are used in the closing tx.payments : Promise<PaymentData[]>,records : Promise<RecordData[]>,refund : Promise<ReturnData>,scripts : Promise<ScriptData[]>,session : Promise<SessionData>,signatures : Promise<SignatureData[]>,// All transactions tied to the contract are here.transactions : Promise<TransactionData[]>fetch()=>Promise<ContractData>join()leave()// These options are only available // during the draft stage of a contract.access : {// Add pubkeys to the member list.add(pubkeys : string[]) : Promise<string[]>,// Remove pubkeys from the member list.remove(pubkeys : string[]) : Promise<string[]>,}// These options are only available // during the draft stage of a contract.
admin : {// Cancel the contract.cancel()// Transfer admin rights to another key.transfer()// Update the details of the contract.update()}
check : {claims()deposits()}
data : {// Add a record to the contract output.add()// Remove a record from the contract output.remove()}
endorse : {
API : EndorseRouter,listadd(hash ?: string) : Promise<EndorseData>remove() : Promise<EndorseData|undefined>}
payment : {// Add a payment output.add()// Remove a payment output.remove()}
profile : {
data : Promise<ProfileData|undefined>,update(template: ProfileTemplate) : Promise<ProfileData|undefined>,tag : {add()remove()}}
script : {// Add a custom script to the contract output.add()// Remove a custom script from the contract output.remove()}
signature : {dataadd(hash ?: string) : Promise<SignatureData|undefined>remove() : Promise<SignatureData|undefined>}}