Skip to main content

encodeMessageFromSignable

Encodes a message from a signable object for a specific signer address.

This function determines whether the signer should sign the transaction payload or envelope based on their role in the transaction (authorizer, proposer, or payer), then encodes the appropriate message for signing.

Payload signers include authorizers and proposers (but not payers) Envelope signers include only payers

The encoded message is what gets signed by the account's private key to create the transaction signature.

Import

You can import the entire package and access the function:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.encodeMessageFromSignable(signable, signerAddress)

Or import directly the specific function:


_10
import { encodeMessageFromSignable } from "@onflow/sdk"
_10
_10
encodeMessageFromSignable(signable, signerAddress)

Usage


_25
import * as fcl from "@onflow/fcl";
_25
_25
// This function is typically used internally by authorization functions
_25
// when implementing custom wallet connectors or signing flows
_25
_25
const signable = {
_25
voucher: {
_25
cadence: "transaction { prepare(acct: AuthAccount) {} }",
_25
authorizers: ["0x01"],
_25
proposalKey: { address: "0x01", keyId: 0, sequenceNum: 42 },
_25
payer: "0x02",
_25
refBlock: "a1b2c3",
_25
computeLimit: 100,
_25
arguments: [],
_25
payloadSigs: []
_25
}
_25
};
_25
_25
// For an authorizer (payload signer)
_25
const authorizerMessage = fcl.encodeMessageFromSignable(signable, "0x01");
_25
console.log("Authorizer signs:", authorizerMessage);
_25
_25
// For a payer (envelope signer)
_25
const payerMessage = fcl.encodeMessageFromSignable(signable, "0x02");
_25
console.log("Payer signs:", payerMessage);

Parameters

signable

  • Type: Signable
  • Description: The signable object containing transaction data and voucher

_10
interface Signable {
_10
voucher: Voucher
_10
}

signerAddress

  • Type: string
  • Description: The address of the signer to encode the message for

Returns

string


Rate this page