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

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

<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