Type/to search
Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
Capability Matrix
Centralized Exchanges
Decentralized Exchanges (DEX)
Prediction Markets
Securities and Futures
On-chain & Custom

Signs messages according to the EIP-191 standard (personal_sign). The signature result is consistent with signMessage of ethers and personal_sign of wallets, and is commonly used in scenarios such as DApp login and off-chain authentication.

exchange.IO(k, message)
exchange.IO(k, message, key)

Examples

Sign a message and recover the signer address through the ecrecover precompiled contract.

javascript
function main() { // Sign text using UTF-8 encoding (the result is consistent with ethers signMessage and wallet // personal_sign) var sig = exchange.IO("signMessage", "hello fmz") Log("digest:", sig.digest, "signature:", sig.signature) // Raw bytes are passed in via {hex: ...} var sig2 = exchange.IO("signMessage", { hex: "0x68656c6c6f20666d7a" }) Log("Consistent with text signature:", sig.signature === sig2.signature) // Use the ecrecover precompiled contract to recover the signer address; the result should match // the current wallet address var ret = exchange.IO("call", "0x0000000000000000000000000000000000000001", "0x" + sig.digest.slice(2) + exchange.IO("encode", "uint8,bytes32,bytes32", sig.v, sig.r, sig.s)) Log("Recovered address:", "0x" + String(ret).slice(-40), "Wallet address:", exchange.IO("address").toLowerCase()) }

Returns

TypeDescription

object

Returns a signature object whose fields are the same as the return value of exchange.IO("sign", ...) (r, s, v, signature, vs). In addition, it contains the digest field, which represents the EIP-191 message hash. Returns a null value when the call fails.

Arguments

NameTypeRequiredDescription

k

string

Yes

Function of the exchange.IO() function. When set to signMessage, it indicates that the function is used to sign a message.

message

string / object

Yes

Message to be signed: when a string is passed in, it is signed using UTF-8 encoding; when raw bytes need to be signed, pass in an object in the format {hex: "0x..."}.

key

string

No

Private key used for signing. When this parameter is not passed in, the private key configured for the exchange object is used by default.

See Also