Use abi.encodePacked(x)

where x is the address. (Thanks @k06a)

Answer from eth on Stack Exchange
🌐
Stack Overflow
stackoverflow.com › questions › 69551020 › trying-to-convert-address-string-to-type-address-in-solidity
ethereum - Trying to convert address string to type address in Solidity - Stack Overflow
pragma solidity ^0.8.0; contract StringToAddress { function stringToAddress(string memory _address) public pure returns (address) { string memory cleanAddress = remove0xPrefix(_address); bytes20 _addressBytes = parseHexStringToBytes20(cleanAddress); return address(_addressBytes); } function remove0xPrefix(string memory _hexString) internal pure returns (string memory) { if (bytes(_hexString).length >= 2 && bytes(_hexString)[0] == '0' && (bytes(_hexString)[1] == 'x' || bytes(_hexString)[1] == 'X')) { return substring(_hexString, 2, bytes(_hexString).length); } return _hexString; } function subs
Discussions

Casting an address to string Solidity 8.0
How does one cast an address to a string? thx More on forum.openzeppelin.com
🌐 forum.openzeppelin.com
8
0
March 8, 2022
solidity - how to convert string to Address? - Ethereum Stack Exchange
I want to convert string data to address type.I know that we can directly use address type in the parameters, but for some reason I want to convert it from string to address. sample code function More on ethereum.stackexchange.com
🌐 ethereum.stackexchange.com
March 21, 2018
ethereum - Solidity: How to type cast string memory to address and uint type? - Stack Overflow
I get the following errors when trying to type cast string memory to address and uint type. TypeError: Explicit type conversion not allowed from "string memory" to "address". More on stackoverflow.com
🌐 stackoverflow.com
blockchain - How can we convert an Ethereum address (string) to Solidity's address type in Javascript in order to pass it to a contract function as an argument? - Stack Overflow
data: "0x08c379a00000000000000......etc" message: "execution reverted: ERC721: mint to to zero address ... I think you don't need to worry about type conversion since solidity manages a string as an address when you pass it through parameters. It seems that tmpdata is returning a Null or maybe ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
MLQ.ai
blog.mlq.ai › solidity-programming-strings-bytes-address-types
Solidity Programming: Strings, Bytes, and Address Types
December 15, 2022 - This is why, in general, it is not very advisable to use strings in smart contracts, although we will still continue working with them for demonstration purposes. One datatype that is very specific to Solidity is the address type.
🌐
TutorialsPoint
tutorialspoint.com › solidity › solidity_strings.htm
Solidity - Strings
In Solidity we can assign String literal to a byte32 type variable easily.
🌐
GeeksforGeeks
geeksforgeeks.org › solidity › type-conversion-in-solidity
Type Conversion in Solidity - GeeksforGeeks
August 9, 2023 - Converting an address to a uint can be useful when performing arithmetic operations while converting it to a string can be beneficial for output formatting or concatenation. ... // Solidity program to implement // Address Conversion // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; contract helloGeeks { function convert() public pure returns (string memory) { address addr = address(0xec6758926Df05d19ea1EFebf0731EFe381Cd6B07); string memory addrStr = toString(addr); return addrStr; } function toString(address _addr) internal pure returns (string memory) { bytes32 value = bytes32(uint256(uint160(_addr))); bytes memory alphabet = "0123456789abcdef"; bytes memory str = new bytes(42); str[0] = '0'; str[1] = 'x'; for (uint256 i = 0; i < 20; i++) { str[2 + i * 2] = alphabet[uint8(value[i + 12] >> 4)]; str[3 + i * 2] = alphabet[uint8(value[i + 12] & 0x0f)]; } return string(str); } }
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 72009474 › solidity-how-to-type-cast-string-memory-to-address-and-uint-type
ethereum - Solidity: How to type cast string memory to address and uint type? - Stack Overflow
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract Test { struct allowedTokenDetails { address admin; uint256 price; uint256 balance; address rewardToken; uint256 timestampAdded; uint256 timestampLastUpdated; } mapping(address => allowedTokenDetails) public allowedTokensData; function setAllowedTokensData(address _token, string[][] memory _data) public { for (uint256 dataIndex = 0; dataIndex < _data.length; dataIndex++) { string memory dataKey = _data[dataIndex][0]; string memory dataValue = _data[dataIndex][1]; if (keccak256(abi.encodePacked(dataKey)) == keccak256(abi.encodePack
🌐
Stack Overflow
stackoverflow.com › questions › 70607845 › how-can-we-convert-an-ethereum-address-string-to-soliditys-address-type-in-ja
blockchain - How can we convert an Ethereum address (string) to Solidity's address type in Javascript in order to pass it to a contract function as an argument? - Stack Overflow
data: "0x08c379a00000000000000......etc" message: "execution reverted: ERC721: mint to to zero address ... I think you don't need to worry about type conversion since solidity manages a string as an address when you pass it through parameters. It seems that tmpdata is returning a Null or maybe an undefined value.
🌐
OpenZeppelin
forum.openzeppelin.com › support › contracts
Casting an address to string Solidity 8.0 - #3 by frangio - Contracts - OpenZeppelin Forum
March 9, 2022 - You can use our Strings library like this: Strings.toHexString(uint256(uint160(msg.sender)), 20);
🌐
GitHub
github.com › miguelmota › solidity-idiosyncrasies
GitHub - miguelmota/solidity-idiosyncrasies: Solidity gotchas, pitfalls, limitations, and idiosyncrasies.
November 30, 2020 - Need to pass an array of single bytes instead of string for addresses; e.g. "0x2680EA4C9AbAfAa63C2957DD3951017d5BBAc518" will be interpreted as a string rather than hex bytes. To pass an address represented in bytes you need to break up the ...
Starred by 345 users
Forked by 45 users
Languages   Solidity 85.7% | JavaScript 14.3% | Solidity 85.7% | JavaScript 14.3%
🌐
Secure-contracts
secure-contracts.com › program-analysis › medusa › docs › src › cheatcodes › to_string.html
toString - Building Secure Contracts
The toString cheatcodes aid in converting primitive Solidity types into strings. Similar to Foundry's behavior, bytes are converted to a hex-encoded string with 0x prefixed. contract TestContract { IStdCheats cheats; constructor() { cheats = IStdCheats(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D); ...
🌐
GitHub
github.com › willitscale › solidity-util
GitHub - willitscale/solidity-util: Solidity Standard Utilities
December 8, 2019 - In a project based on Truffle framework you may then import and bind the libraries to the appropriate data types as seen below: pragma solidity ^0.5.0; import "solidity-util/lib/Strings.sol"; import "solidity-util/lib/Integers.sol"; import "solidity-util/lib/Addresses.sol"; contract MyContract { using Strings for string; using Integers for uint; using Addresses for address; using Addresses for address payable; }
Starred by 131 users
Forked by 34 users
Languages   Solidity 100.0% | Solidity 100.0%
🌐
Stack Exchange
ethereum.stackexchange.com › questions › 115455 › comparing-address-string-to-address
solidity - Comparing address string to address - Ethereum Stack Exchange
Converting one to the other is nothing fancy: just go through the string character by character and convert each one to a 4-bit number (i.e. just a value between 0 and 15). Then use masking to put that 4-bit number at the right position in an ...
🌐
Medium
jeancvllr.medium.com › solidity-tutorial-all-about-addresses-ffcdf7efc4e7
Solidity Tutorial : all about Addresses | by Jean Cvllr | Medium
April 10, 2026 - Press enter or click to view image in full size · Introduction · What is (technically) an Ethereum Address ? Basic of Addresses in Solidity & address literals · Address vs address payable · Methods available with addresses (including call(), delegatecall() and staticcall() ) Types conversions between addresses and address payable ·
🌐
GitHub
gist.github.com › ageyev › 779797061490f5be64fb02e978feb6ac
StringsAndBytes.sol · GitHub
* Pads the bytes16 into bytes32 that can be converted back into a string. */ function toHex16 (bytes16 data) internal pure returns (bytes32 result) { result = bytes32 (data) & 0xFFFFFFFFFFFFFFFF000000000000000000000000000000000000000000000000 | (bytes32 (data) & 0x0000000000000000FFFFFFFFFFFFFFFF00000000000000000000000000000000) >> 64; result = result & 0xFFFFFFFF000000000000000000000000FFFFFFFF000000000000000000000000 | (result & 0x00000000FFFFFFFF000000000000000000000000FFFFFFFF0000000000000000) >> 32; result = result & 0xFFFF000000000000FFFF000000000000FFFF000000000000FFFF000000000000 | (re
🌐
BitcoinTalk
bitcointalk.org › index.php
Convert Ethereum ABI Address To String (Solidity)
Bitcoin Forum > Alternate cryptocurrencies > Altcoin Discussion > Convert Ethereum ABI Address To String (Solidity)
🌐
Moralis
studygroup.moralis.io › ethereum smart contract programming 201
Converting string to type address - in JavaScript or Solidity? - Ethereum Smart Contract Programming 201 - Moralis Academy Forum
March 14, 2021 - Hi everyone, I am working on converting a html string input to a type address. The idea is to have an input field on the website, so that contract owner can input an address that then shall be approved in the contract. So I have to convert the input string and pass it as type address to the ...