deploy static method
Future<SignalingContract>
deploy({
- required String rpcUrl,
- required Credentials credentials,
- List<
ContractParameter> constructorParams = const [],
Deploy new contract instance
Implementation
static Future<SignalingContract> deploy({
required String rpcUrl,
required Credentials credentials,
List<ContractParameter> constructorParams = const [],
}) async {
final client = Web3Client(rpcUrl, Client());
// Encode constructor parameters if any
String deployData = contractBytecode;
if (constructorParams.isNotEmpty) {
deployData = _encodeDeployData(contractBytecode, constructorParams);
}
final transaction = Transaction(
from: credentials.address,
data: hexToBytes(deployData),
);
final txHash = await client.sendTransaction(credentials, transaction);
// Wait for transaction receipt and get contract address
TransactionReceipt? receipt;
int attempts = 0;
while (receipt == null && attempts < 60) {
await Future.delayed(const Duration(seconds: 1));
receipt = await client.getTransactionReceipt(txHash);
attempts++;
}
if (receipt == null) {
throw Exception('Contract deployment failed: transaction receipt not found after 60 seconds');
}
final contractAddr = receipt.contractAddress;
if (contractAddr == null) {
throw Exception('Contract deployment failed: no contract address in receipt');
}
// Return connected instance
return connect(
rpcUrl: rpcUrl,
contractAddress: contractAddr,
credentials: credentials,
);
}