3

I have this source code

pragma solidity ^0.4.21;

// Relevant part of the CaptureTheEther contract.
contract CaptureTheEther {
    mapping (address => bytes32) public nicknameOf;

    function setNickname(bytes32 nickname) public {
        nicknameOf[msg.sender] = nickname;
    }
}

// Challenge contract. You don't need to do anything with this; it just verifies
// that you set a nickname for yourself.
contract NicknameChallenge {
    CaptureTheEther cte = CaptureTheEther(msg.sender);
    address player;

    // Your address gets passed in as a constructor parameter.
    function NicknameChallenge(address _player) public {
        player = _player;
    }

    // Check that the first character is not null.
    function isComplete() public view returns (bool) {
        return cte.nicknameOf(player)[0] != 0;
    }
}

So is it possible to call setNickname(bytes32 nickname) with MetaMask using the Transaction Data field?

Further, if I have set the nickname - how can I call receive my nickname from mapping (address => bytes32) public nicknameOf; with MetaMask using the Transaction Data field?

  • I would highly recommend using Remix. I don't think MetaMask gives you any way to manually enter the data field, and you'd still want some tool to help figure out the right data to send. – user19510 Jun 29 '18 at 3:37
1

So is it possible to call setNickname(bytes32 nickname) with MetaMask using the Transaction Data field?

You can do so by calling the function through its identifier and providing the according data.

Example: I want to call your function setNickname(bytes32 nickname) and set the name to "Teddy".

  1. I insert the code into Remix IDE and deploy it in the JS EVM.
  2. I convert Teddy to bytes, which is 5465646479
  3. I call the function with "0x5465646479"
  4. I check the details of the transaction: input
  5. ...and then click on the copy icon next to the input field.

This is the encoded data to paste into the datafield in metamask when wishing to execute a contract function on a transaction.

Hint: You can find out here how to generate this input data with a script yourself ! :)

| improve this answer | |
-3

MetaMask does not allow you to interact with smart contracts simply because smart contract functions/methods can be customised and varies from one contract to the other.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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