5.7.1 Java  Script
5.7.1.1 Types
5.7.1.2 loader.mjs
5.7.1.3 Accounts
5.7.1.4 Contracts
5.7.1.5 Network Utilities
5.7.1.6 Provider Selection
5.7.1.7 Utilities
5.7.1.8 ask.mjs
5.7.1.4 Contracts
On this page:
deploy
get  Info
attach
5.7.1.4.1 View Access
get  Views
5.7.1.4 Contracts

These functions create and interact with contract representations.

acc.deploy(bin) => ctc 

Returns a Reach contract abstraction after starting the deployment of a Reach DApp contract based on the bin argument provided. This bin argument is the "input.mjs" module produced by the JavaScript backend. This function does not block on the completion of deployment. To wait for deployment, see ctc.getInfo.

ctc.getInfo() => Promise<ctcInfo> 

Returns a Promise for an object that may be given to attach to construct a Reach contract abstraction representing this contract. This object may be stringified with JSON.stringify for printing and parsed again with JSON.parse without any loss of information. The Promise will only be resolved after the contract is actually deployed on the network. If you are using {deployMode: 'firstMsg'}, avoid blocking 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.

acc.attach(bin, ctcInfoP) => ctc 

Returns a Reach contract abstraction based on a deployed Reach DApp contract provided in the ctcInfo argument (or a Promise for ctcInfo) and the bin argument. This bin argument is the "input.mjs" module produced by the JavaScript backend.

5.7.1.4.1 View Access

Views are defined in application initialization and then they are set in consensus steps. Both of these steps are in Reach. They are accessed by frontends by using the Reach standard library of the frontend language, such as JavaScript.

ctc.getViews() => Object 

Returns an object representing the views of the contract. This object mirrors the view hierarchy, so if X.Y is a view, then ctc.getViews().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.getViews().NFT.owner() is either ['Some', Owner] or ['None', null].