Class: Contract

fabric-network. Contract

Represents a smart contract (chaincode) instance in a network. Applications should get a Contract instance using the networks's getContract method.

new Contract()

Methods


<async> addContractListener(listenerName, callback [, options] [, eventHub])

Create a commit event listener for this transaction.
Parameters:
Name Type Argument Description
listenerName string The name of the listener
callback function This callback will be triggered when a transaction commit event is emitted. It takes parameters of error, event payload, block number, transaction ID and status
options module:fabric-network.Network~ListenerOptions <optional>
Optional. Options on registrations allowing start and end block numbers.
eventHub ChannelEventHub <optional>
Optional. Used to override the event hub selection
Returns:
Type
module:fabric-network~CommitEventListener

addDiscoveryInterest(interest)

Provide a Discovery Interest settings to help the peer's discovery service build an endorsement plan. This chaincode Id will be include by default in the list of discovery interests. If this contract's chaincode is in one or more collections then use this method with this chaincode Id to change the default discovery interest to include those collection names.
Parameters:
Name Type Description
interest DiscoveryInterest These will be added to the existing discovery interests to be used as the "endorsement_hint" attribute of the request when the module:fabric-network.Transaction#submit performs a Channel#sendTransactionProposal

createTransaction(name)

Create an object representing a specific invocation of a transaction function implemented by this contract, and provides more control over the transaction invocation. A new transaction object must be created for each transaction invocation.
Parameters:
Name Type Description
name String Transaction function name.
Returns:
A transaction object.
Type
module:fabric-network.Transaction

<async> evaluateTransaction(name [, args])

Evaluate a transaction function and return its results. The transaction function name will be evaluated on the endorsing peers but the responses will not be sent to the ordering service and hence will not be committed to the ledger. This is used for querying the world state. This function is equivalent to calling createTransaction(name).evaluate().
Parameters:
Name Type Argument Description
name string Transaction function name.
args string <optional>
<repeatable>
Transaction function arguments.
Returns:
Payload response from the transaction function.
Type
Buffer

getDiscoveryInterests()

Retrieve the Discovery Interest settings that will help the peer's discovery service build an endorsement plan.
Returns:
- This will be used as the endorsement_hint when the Channel performs the Channel#sendTransactionProposal
Type
Array.<DiscoveryInterest>

<async> submitTransaction(name [, args])

Submit a transaction to the ledger. The transaction function name will be evaluated on the endorsing peers and then submitted to the ordering service for committing to the ledger. This function is equivalent to calling createTransaction(name).submit().
Parameters:
Name Type Argument Description
name string Transaction function name.
args string <optional>
<repeatable>
Transaction function arguments.
Throws:
If the transaction was successfully submitted to the orderer but timed out before a commit event was received from peers.
Type
module:fabric-network.TimeoutError
Returns:
Payload response from the transaction function.
Type
Buffer