Once you've instantiated your wallet in an unlocked state using one of the previously discussed methods, you can sign a message with wallet.signMessage
. Below is a full example of how to sign and recover a message.
// #import { WalletUnlocked, hashMessage, Signer };
const wallet = WalletUnlocked.generate({
provider,
});
const message = 'doc-test-message';
const signedMessage = await wallet.signMessage(message);
const hashedMessage = hashMessage(message);
const recoveredAddress = Signer.recoverAddress(hashedMessage, signedMessage);
You can also sign a transaction by using wallet.signTransaction
. Below is a full example of how to sign and recover a transaction.
// #import { Provider, Wallet, Signer };
const provider = await Provider.create(FUEL_NETWORK_URL);
const wallet = Wallet.fromPrivateKey(PRIVATE_KEY, provider);
const signedTransaction = await wallet.signTransaction(SCRIPT_TX_REQUEST);
const chainId = wallet.provider.getChainId();
const verifiedAddress = Signer.recoverAddress(
SCRIPT_TX_REQUEST.getTransactionId(chainId),
signedTransaction
);