SmartContractController class final
Smart contract controller providing query and call functionality.
Extends BaseController to provide smart contract interaction methods. Uses internal Factory, QueryRunner, and EventRunner components.
Supports two modes of operation:
- With ABI: Arguments are native Dart values, responses are parsed
- Without ABI: Arguments must be TypedValue or Uint8List, returns raw data
Example with ABI
final controller = SmartContractController(
contractAddress: SmartContractAddress.fromBech32('erd1qqqqqq...'),
networkProvider: apiProvider,
abi: SmartContractAbi.fromJson(abiJson),
);
final result = await controller.query(endpointName: 'getTotal');
print('Total: ${result.first}');
final tx = await controller.call(
account: myAccount,
nonce: Nonce(42),
endpointName: 'deposit',
arguments: [BigInt.from(1000)],
options: BaseControllerInput(gasLimit: GasLimit(10000000)),
);
Example without ABI
final controller = SmartContractController.withoutAbi(
contractAddress: SmartContractAddress.fromBech32('erd1qqqqqq...'),
networkProvider: apiProvider,
);
final result = await controller.queryRaw(
endpointName: 'getBalance',
arguments: [AddressValue.fromBech32('erd1user...')],
);
final tx = await controller.callRaw(
account: myAccount,
nonce: Nonce(42),
endpointName: 'deposit',
arguments: [BigUIntValue(BigInt.from(1000))],
options: BaseControllerInput(gasLimit: GasLimit(10000000)),
);
- Inheritance
-
- Object
- BaseController
- SmartContractController
- Annotations
-
- @immutable
Constructors
- SmartContractController({required Address contractAddress, required NetworkProvider networkProvider, required SmartContractAbi abi, IGasLimitEstimator? gasLimitEstimator, Logger? logger})
- Creates controller with contract address, network provider, and ABI.
- SmartContractController.withoutAbi({required Address contractAddress, required NetworkProvider networkProvider, IGasLimitEstimator? gasLimitEstimator, Logger? logger})
- Creates controller without ABI for raw TypedValue or Uint8List arguments.
Properties
- abi → SmartContractAbi
-
The smart contract ABI.
no setter
- contractAddress → Address
-
The target smart contract address.
final
- gasLimitEstimator → IGasLimitEstimator?
-
Optional gas limit estimator for automatic gas calculation.
finalinherited
- hasAbi → bool
-
Whether this controller has an ABI for validation and parsing.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- logger → Logger?
-
Optional logger for transaction setup operations.
finalinherited
- networkProvider → NetworkProvider
-
The network provider for API calls.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addExtraGasLimitIfRequired(
Transaction transaction) → Transaction -
Adds extra gas limit for guarded or relayed transactions.
inherited
-
awaitCompletedDeploy(
String txHash) → Future< SmartContractDeployOutcome> - Awaits a deploy transaction until completion and returns the parsed outcome.
-
awaitCompletedExecute(
String txHash, {String? function}) → Future< ParsedSmartContractCallOutcome> - Awaits an execute transaction until completion and returns the parsed outcome.
-
call(
{required IAccount account, required Nonce nonce, required String endpointName, List arguments = const <dynamic>[], required BaseControllerInput options, List< TokenTransferValue> tokenTransfers = const <TokenTransferValue>[], Balance? value}) → Future<Transaction> - Creates and signs a smart contract call transaction.
-
callRaw(
{required IAccount account, required Nonce nonce, required String endpointName, List arguments = const <dynamic>[], required BaseControllerInput options, List< TokenTransferValue> tokenTransfers = const <TokenTransferValue>[], Balance? value}) → Future<Transaction> - Creates and signs a smart contract call transaction without ABI.
-
createTransactionForDeploy(
{required Address sender, required Nonce nonce, required Uint8List bytecode, required GasLimit gasLimit, Uint8List? codeMetadata, String vmType = '0500', List< Uint8List> arguments = const <Uint8List>[]}) → Transaction - Creates an unsigned deploy transaction for this contract's bytecode.
-
createTransactionForUpgrade(
{required Address sender, required Nonce nonce, required Uint8List bytecode, required GasLimit gasLimit, Uint8List? codeMetadata, List< Uint8List> arguments = const <Uint8List>[]}) → Transaction - Creates an unsigned upgrade transaction for this contract.
-
getAllEventDefinitions(
) → List< EventDefinition> - Gets all event definitions from the ABI.
-
getEndpoint(
String endpointName) → AbiEndpoint - Gets an endpoint definition from the ABI.
-
getEventDefinition(
String eventIdentifier) → EventDefinition? - Gets a specific event definition by identifier.
-
getEventHistory(
{required String eventIdentifier, int limit = 25}) → Future< List< ParsedEvent> > - Fetches recent events from the contract's transaction history.
-
getMutableEndpoints(
) → List< AbiEndpoint> - Gets all mutable (non-view) endpoints from the ABI.
-
getViewEndpoints(
) → List< AbiEndpoint> - Gets all view endpoints from the ABI.
-
hasEndpoint(
String endpointName) → bool - Checks if an endpoint exists in the ABI.
-
hasEvent(
String eventIdentifier) → bool - Checks if an event exists in the ABI.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parseDeploy(
TransactionOnNetwork transaction) → SmartContractDeployOutcome - Parses a completed deploy transaction into a structured outcome.
-
parseExecute(
{required TransactionOnNetwork transaction, String? function}) → ParsedSmartContractCallOutcome - Parses a completed execute transaction into a structured outcome.
-
parseQueryResponse(
{required SmartContractQueryResponse response, required String endpointName}) → List - Decodes a raw SmartContractQueryResponse into native ABI values.
-
query(
{required String endpointName, List arguments = const <dynamic>[], Address? caller, Balance? value}) → Future< QueryResult> - Executes a smart contract query and returns parsed results.
-
queryEvents(
{required String txHash, required String eventIdentifier}) → Future< List< ParsedEvent> > - Fetches and parses events from a specific transaction.
-
queryEventsBatch(
{required List< String> txHashes, required String eventIdentifier}) → Future<Map< String, List< >ParsedEvent> > - Fetches and parses events from multiple transactions in batch.
-
queryRaw(
{required String endpointName, List arguments = const <dynamic>[], Address? caller, Balance? value}) → Future< RawQueryResult> - Executes a smart contract query without ABI and returns raw results.
-
setTransactionGasOptions(
Transaction transaction, BaseControllerInput options) → Future< Transaction> -
Sets transaction gas price and limit with automatic estimation.
inherited
-
setupAndSignTransaction(
Transaction transaction, BaseControllerInput options, Nonce nonce, IAccount sender) → Future< Transaction> -
Sets up and signs transaction with common options and account signature.
inherited
-
setVersionAndOptionsForGuardian(
Transaction transaction) → Transaction -
Sets version and options for guarded transactions (guardian present).
inherited
-
streamAllEvents(
{Duration pollingInterval = const Duration(seconds: 2), String? startFrom}) → Stream< ParsedEvent> - Creates a real-time stream of ALL events by polling the contract.
-
streamEvents(
{required String eventIdentifier, Duration pollingInterval = const Duration(seconds: 2), String? startFrom}) → Stream< ParsedEvent> - Creates a real-time stream of events by polling the contract.
-
toString(
) → String -
A string representation of this object.
inherited
-
watchTransaction(
{required String txHash, required String eventIdentifier, Duration timeout = const Duration(minutes: 1), Duration pollingInterval = const Duration(seconds: 1)}) → Future< List< ParsedEvent> > - Watches a transaction until completion and returns parsed events.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited