pragma solidity ^0.4.25;

contract Purchase {
    address public sellerAddress;

    constructor (address _sellerAddress) {
        sellerAddress = _sellerAddress;

contract Buyer is Purchase {
    address public buyerAddress;
    string pass;
    bytes32 hashpass;

    modifier onlyBuyer() {
        require(msg.sender == buyerAddress);

    constructor(string _pass) {
        buyerAddress = msg.sender;
        pass = _pass;

    function stringToBytes32(string pass) returns (bytes32 hashpass) {
        hashpass = bytes32(pass);

    function generateHashPass() public {


1 Answer 1


If you want to convert a string to a bytes32, you can use the method described in this post: How to convert a string to bytes32?

However, it looks like you're trying to take a hash of the string, which can be done with a hashing function such as keccak256.

hashpass = keccak256(pass);
  • Thanks for the answer, another query from same case I want to withdraw 1 ether from particular buyer's account, here withdraw will be performed by seller. How can I implement this condition?
    – Rudrika
    Jan 7, 2019 at 11:27
  • It's impossible for one person to withdraw eth from someone else's Ethereum account, so either the buyer would have to send the eth directly to the seller, or the buyer should send money to your smart contract, which can only be withdrawn by the seller under certain conditions. Jan 7, 2019 at 11:53
  • Yes. I want the buyer should send money to my account and that only withdrawn by seller. But how can I implement this in solidity?
    – Rudrika
    Jan 7, 2019 at 12:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.