Skip to main content

getCode

Callable

  • getCode<ReturnFormat>(web3Context: Web3Context<EthExecutionAPI, any>, address: string, blockNumber?: BlockNumberOrTag, returnFormat: ReturnFormat): Promise<string>

  • Get the code at a specific address.


    Type parameters

    • ReturnFormat: DataFormat

    Parameters

    • web3Context: Web3Context<EthExecutionAPI, any>

      (Web3Context) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.

    • address: string

      The address to get the code from.

    • blockNumber: BlockNumberOrTag = web3Context.defaultBlock

      (BlockNumberOrTag defaults to Web3Eth.defaultBlock) Specifies what block to use as the current state for the code query.

    • returnFormat: ReturnFormat

      (DataFormat defaults to DEFAULT_RETURN_FORMAT) Specifies how the return data should be formatted.

    Returns Promise<string>

    The data at the provided address.

    web3.eth.getCode("0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234").then(console.log);
    > "0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"

    web3.eth.getCode(
    "0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234",
    undefined,
    { number: FMT_NUMBER.HEX , bytes: FMT_BYTES.BUFFER }
    ).then(console.log);
    > <Buffer 30 78 36 30 30 31 36 30 30 30 38 30 33 35 38 31 31 61 38 31 38 31 38 31 31 34 36 30 31 32 35 37 38 33 30 31 30 30 35 62 36 30 31 62 36 30 30 31 33 35 ... >