let provider_url = 

this.web3Provider = new Web3.providers.HttpProvider(provider_url);
window.web3_ = new Web3(this.web3Provider);

let account = "0x25bA673A96acadD7A02f4c5834Ba80C1AF6b7758";

          let nonce = window.web3_.toHex(window.web3_.eth.getTransactionCount(account));

          let myPrivateKey = "****";

          let privateKey = new Buffer(myPrivateKey, "hex");
          let functionName = "markAttendance";
          let types = ["address", "uint", "uint256"];
          let args = [attendeeAddress, opinion, date];
          let fullName = functionName + "(" + types.join() + ")";
          let signature = CryptoJS.SHA3(fullName, {outputLength: 256}).toString(CryptoJS.enc.Hex).slice(0, 8);
          let dataHex = signature + coder.encodeParams(types, args);
          let data = "0x" + dataHex;
          // let nonce = web3.toHex();
          let gasPrice = window.web3_.toHex(20000000000); // 20 Gwei
          let gasLimitHex = window.web3_.toHex(4700000);

          let rawTx = {
            'nonce': nonce,
            'gasPrice': gasPrice,
            'gasLimit': gasLimitHex,
            'from': account,
            'to': '0xf77c958bdffee94c3f53eb763cffd646cde336d9', 
            'data': data,
            'value': window.web3_.toHex(window.web3_.toWei("0.5", "ether")),
          let tx = new Tx(rawTx);
          let serializedTx = '0x' + tx.serialize().toString('hex');
window.web3_.eth.sendRawTransaction(serializedTx, function (err, txHash) {
  console.log(err, txHash)


contract MarkAttendance {

struct AttendeeDetails {
    address attendance_giver;
    address attendee;
    uint attendance_opinion;
    uint256 timestamp;
    uint256 date_of_attendance;

//mapping of structure  for storing the attendeeDetails
mapping(uint => AttendeeDetails) public attendeeDetails;
uint public attendeeDetailsCount;

function markAttendance(address _attendee, uint _attendance_opinion, uint256 _date) public {
    attendeeDetailsCount ++;
    attendeeDetails[attendeeDetailsCount] = AttendeeDetails(msg.sender, _attendee, _attendance_opinion, now, _date);

I am getting TXHASH but transaction is getting cancelled every time . what might be the issue i am doing ? can anyone suggest me any solution for this .

It works fine if I call the method from truffle console. I get a successful transaction receipt .

please find the screenshot

  • 1
    The transaction was reverted. To know why, you'd have to look at the code for the contract.
    – user19510
    Dec 8, 2018 at 6:49
  • Does it work if you send it as normal transaction ? I.e. let node sign it instead of signing it on client side ? If that works, it can be a next step for troubleshooting. Since there is a "revert", it might fail as normal transaction as well. Dec 8, 2018 at 6:50
  • You provided contract account in rawTx is to:0x7145dc9549f548bef6bb2916e063cc0404d2e8d9 and your actually contract address is 0x7145dc9549f548bEF6BB2916e063CC0404d2E8d8. there is slight change in last character 9 from 8. correct it. Dec 8, 2018 at 7:20
  • @MaheshRajput Although that certainly looks like an issue, the transaction in the screenshot seems to going to the correct address: ropsten.etherscan.io/tx/….
    – user19510
    Dec 8, 2018 at 7:36
  • Yes @smarx I agree with you, but I am just asking to sibabrat to correct that change in question so anyone doesn't west their time to find another error by this code. Dec 8, 2018 at 7:40

1 Answer 1


Your function selector calculation is incorrect. You're using "uint" instead of "uint256". (The former is an alias for the latter, but the latter should always be used when calculating a function selector.)

Change this line:

let types = ["address", "uint", "uint256"];

to this:

let types = ["address", "uint256", "uint256"];


You're also attaching ether to the transaction, but the function you're calling is not payable so it won't accept ether. To fix this, drop the value: ... line.


Your Answer

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

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