PrivateKeySigner.fromHex constructor

PrivateKeySigner.fromHex(
  1. String privateKeyHex, {
  2. required Web3Client getClient(),
  3. required int getChainId(),
})

Factory from hex private key string.

Implementation

factory PrivateKeySigner.fromHex(
  String privateKeyHex, {
  required Web3Client Function() getClient,
  required int Function() getChainId,
}) {
  final normalized = privateKeyHex.trim().startsWith('0x')
      ? privateKeyHex.trim()
      : '0x${privateKeyHex.trim()}';
  final creds = EthPrivateKey.fromHex(normalized);
  return PrivateKeySigner(
    credentials: creds,
    getClient: getClient,
    getChainId: getChainId,
  );
}