Skip to main content

sign

Callable

  • sign<ReturnFormat>(web3Context: Web3Context<EthExecutionAPI, any>, message: Bytes, addressOrIndex: string | number, returnFormat: ReturnFormat): Promise<string | { message?: string; messageHash: string; r: string; s: string; signature: string; v: string }>

  • Type parameters

    Parameters

    Returns Promise<string | { message?: string; messageHash: string; r: string; s: string; signature: string; v: string }>

    The signed message.

    // Using an unlocked account managed by connected RPC client
    web3.eth.sign("0x48656c6c6f20776f726c64", "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe").then(console.log);
    > "0x30755ed65396facf86c53e6217c52b4daebe72aa4941d89635409de4c9c7f9466d4e9aaec7977f05e923889b33c0d0dd27d7226b6e6f56ce737465c5cfd04be400"

    // Using an unlocked account managed by connected RPC client
    web3.eth.sign("0x48656c6c6f20776f726c64", "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.BUFFER }).then(console.log);
    > <Buffer 30 78 33 30 37 35 35 65 64 36 35 33 39 36 66 61 63 66 38 36 63 35 33 65 36 32 31 37 63 35 32 62 34 64 61 65 62 65 37 32 61 61 34 39 34 31 64 38 39 36 ... >

    // Using an indexed account managed by local Web3 wallet web3.eth.sign(“0x48656c6c6f20776f726c64”, 0).then(console.log);

    “0x30755ed65396facf86c53e6217c52b4daebe72aa4941d89635409de4c9c7f9466d4e9aaec7977f05e923889b33c0d0dd27d7226b6e6f56ce737465c5cfd04be400”