5.7.1 Java  Script Types loader.mjs Account Handles Contract Handles Network Utilities Provider Selection Utilities ask.mjs
On this page:
get  Info
get  Contract  Address
get  Views Contract Handles

In order to interact with a deployed contract, you must construct a contract handle from an account.

acc.contract(bin, ?info) => ctc 

Returns a Reach contract handle based on the bin argument provided with access to the account acc. This bin argument is the "input.mjs" module produced by the JavaScript backend.

If info is provided, it must be a Contract value, or a Promise that eventually yields a Contract value. Typically, the deployer of a contract with not provide info, while users of a contract will. In an automated, single instance program, ctc.getInfo() is typically used to acquire info; while in non-automated programs, an application uses out-of-band communication, such as an external database or user input, to acquire the info argument.

The first publishing participant will attempt deploy a contract for application. If info was provided, an error will be thrown. This deployment can only happen one time, so subsequent attempts will fail with an error.

This function does not block.

acc.deploy(bin) => ctc

This deprecated function is an abbreviation of acc.contract(bin).

acc.attach(bin, info) => ctc 

This deprecated function is an abbreviation of acc.contract(bin, info).

ctc.getInfo() => Promise<ctcInfo> 

Returns a Promise for a Contract value that may be given to contract to construct a Reach contract handle for this contract. This object may be stringified with JSON.stringify for printing and parsed again with JSON.parse without any loss of information.

If ctc will deploy the program, then the Promise will only be resolved after the contract is actually deployed on the network, thus you cannot block on this Promise with await until after the first publish has occurred. Awaiting getInfo too early may cause your program to enter a state of deadlock. It is safer to make an interact function that receives getContract() from the Reach program.

ctc.getContractAddress() => Promise<Address> 

Returns a Promise for the Address of the connected Reach contract.

Contract handles provide access to the interface of the compiled backend, bin, that they were constructed with.

ctc.participants // {[name: string]: (interact:Object) => Promise}


An object where the keys are the participant names and the values are function that accept an interact object and return a Promise that completes when the participant ends.

acc.contract(backend).p.Alice(io) is equivalent to backend.Alice(acc.contract(backend), io), but does not require duplication of the backend component.

Views are defined in application initialization and then they are set in consensus steps. Both of these steps are in Reach. This section is about accessing them in JavaScript frontends.

ctc.views // {[name: string]: {[fun:string]: (...args) => Promise<res>}}


An object that mirrors the view hierarchy, so if X.Y is a view, then ctc.views.X.Y is a view function. A view function accepts the arguments of the view and returns a Promise that results in the value of the view wrapped in a Maybe type (because the view may not be bound.) For example, if NFT.owner is a view with no arguments that represents the Address that owns an NFT, then await ctc.v.NFT.owner() is either ['Some', Owner] or ['None', null].

ctc.getViews() => Object 

This deprecated function is an abbreviation of ctc.views.