signOffChain static method
Signs an off-chain transaction using the provided credentials and transaction data.
credentials
is the private key used for signing.
from
is the address of the sender.
to
is the address of the receiver.
data
is the transaction data to be sent.
nonce
is the nonce of the transaction.
value
is the optional amount of Ether to be sent.
gasPrice
is the optional gas price for the transaction.
gasLimit
is the optional gas limit for the transaction.
Returns a hex string representing the signed transaction.
Implementation
static String signOffChain(
EthPrivateKey credentials,
String from,
String to,
String data,
String nonce, {
BigInt? value,
BigInt? gasPrice,
BigInt? gasLimit,
}) {
final List<String> inputArr = [
'0x19',
'0x00',
from,
to,
hexZeroPad(hexlify(value ?? BigInt.from(0)), 32),
data,
nonce,
hexZeroPad(hexlify(gasPrice ?? BigInt.from(0)), 32),
hexZeroPad(
hexlify(gasLimit ?? BigInt.from(Variables.DEFAULT_GAS_LIMIT)), 32)
];
final String input =
'0x${inputArr.map((hexStr) => hexStr.toString().substring(2)).join('')}';
final Uint8List messagePayload = keccak256(hexToBytes(input));
final Uint8List signature = credentials.signPersonalMessageToUint8List(
messagePayload,
);
return bytesToHex(signature, include0x: true);
}