0

I am unable to call my smart contract in Metamask over Ganache.

These were the steps I took:

  • developed the contract
  • tested it successfully using truffle test
  • set up a Ganache network and migrated the contract to the network
  • in Metamask, connected to the private Ganache network and one of the accounts via private key
  • Then proceeded to make a payment from the account of 5 eth and using another account as the "transaction data" in Metamask (see below - the pay contract expects a single address as an argument)

This is the error I'm getting:

enter image description here

This is how I called the contract:

enter image description here

Pay.sol

pragma solidity ^0.4.17;

/// @title Pay - Facilitates payments.
contract Pay {
    event Payment(
        address _from,
        address _to,
        uint amount
    );

    /// @dev Makes a payment.
    /// @param _to Address to pay to.
    function pay(address _to) public payable {
        require(msg.value > 0);
        _to.transfer(msg.value);
        Payment(msg.sender, _to, msg.value);
    }
}

2_pay_migration.js

var Pay = artifacts.require("Pay");

module.exports = function(deployer) {
    deployer.deploy(Pay);
}
1
  • Please add the full transaction data included with the transaction. ABI helps too Mar 16, 2018 at 8:09

1 Answer 1

0

That's not how transaction data works. The correct data would be the first four bytes of the keccak256 hash of "pay(address)" followed by the address, left-padded to be 32 bytes wide. As you can imagine, it's unusual to construct that payload by hand. :-)

1
  • Thank you, I was able to do this with myetherwallet + Metamask.
    – Peteris
    Mar 17, 2018 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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