1

transactionHash: '0x2451df71c0d4f08c93d0cbee0af89c13e938a02e69357737054c7f516022f70e'

Here is the transaction hash. I have successfully sent a string message to the contract, received receipt json response, BUT, transaction was not seen on the etherescan anyway. Help plzzz.

UPDATE: I got this message!

Error: Transaction was not mined within 750 seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!

UPDATE: No.2:

/* GET home page. */
router.get('/', function(req, res, next) { 

  let provider = new HDWalletProvider(ethMainPrivateKey, "https://rinkeby.infura.io/v3/AUTHORIZATION");
  var web3 = new Web3(provider);

  var contractAddress="0x2d3e9fb71a2b864dd264a83e69db647b0bd0f888";
  var contractAbi = [
    {
      "constant": false,
      "inputs": [],
      "name": "fallback",
      "outputs": [],
      "payable": true,
      "stateMutability": "payable",
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [],
      "name": "kill",
      "outputs": [],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [],
      "name": "receive",
      "outputs": [],
      "payable": true,
      "stateMutability": "payable",
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [
        {
          "name": "newGreeting",
          "type": "string"
        }
      ],
      "name": "setGreeting",
      "outputs": [],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "function"
    },
    {
      "inputs": [],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "constructor"
    },
    {
      "constant": true,
      "inputs": [
        {
          "name": "idx",
          "type": "uint256"
        }
      ],
      "name": "getGreeting",
      "outputs": [
        {
          "name": "",
          "type": "string"
        },
        {
          "name": "",
          "type": "address"
        }
      ],
      "payable": false,
      "stateMutability": "view",
      "type": "function"
    },
    {
      "constant": true,
      "inputs": [],
      "name": "repliesCount",
      "outputs": [
        {
          "name": "",
          "type": "uint256"
        }
      ],
      "payable": false,
      "stateMutability": "view",
      "type": "function"
    }
  ]

  var myContract = new web3.eth.Contract(contractAbi, contractAddress);  
  var greetingMessage = "This is the THIRD greeting message!"

  const tx = {
    // this could be provider.addresses[0] if it exists
    from: ethMainAddress, 
    // target address, this could be a smart contract address
    to: contractAddress, 
    // optional if you want to specify the gas limit 
    gas: 1000000, 
    gasPrice: 1000000000, // 1 GWEI - 2 billion wei
    
    // this encodes the ABI of the method and the arguements
    data: myContract.methods.getGreeting(2).encodeABI(),
 
    nonce: 100

  }; 

  const signPromise = web3.eth.accounts.signTransaction(tx, ethMainPrivateKey);

  signPromise.then((signedTx) => {
    // raw transaction string may be available in .raw or 
    // .rawTransaction depending on which signTransaction
    // function was called
    console.log(signedTx) // last hash: 0x5b696f6dfaef41e1a6d7c5cf0914d49910ab2c539de108874f9cc9b3a4b7b960
    const sentTx = web3.eth.sendSignedTransaction(signedTx.raw || signedTx.rawTransaction);
    sentTx.on("receipt", receipt => {
      // do something when receipt comes back
      console.log("receipt" + JSON.stringify(receipt))
    });
    sentTx.on("error", err => {
      // do something on transaction error
      console.log("error" + err) 
    });
  }).catch((err) => {
    // do something when promise fails
      console.log("err" + JSON.stringify(err)) 
  }); 
 
  

  res.render('index', { title: 'Express' });
});

UPDATE No.3: I also remember that contract method call should not burn gas, but this medhod has a method has some input parameter, I thought it may burn gas, then I send transaction.

UPDATE No.4: I added contract code.

pragma solidity ^0.5.1;

contract Greeter {
    
    struct GreetingMessage {
        string message;
        address owner;
    } 
    
    modifier onlyOwner() {
        require(owner == msg.sender, "Only owner can execute this command!");
        _; //if owner calls sth, continue execution!
    }  
    
    address payable owner;
    GreetingMessage[] greetings;
    uint public repliesCount;
    
    constructor() public {
        owner = msg.sender;
        greetings.push(GreetingMessage("Hello, Ramazan", msg.sender)); 
    }

    
    function receive() external payable {}
    
    function fallback() external payable {}

    function getGreeting(uint idx) public onlyOwner view returns (string memory, address) {
        GreetingMessage storage greeting = greetings[idx];
        return (greeting.message, greeting.owner);
    }
    
    function setGreeting(string memory newGreeting) public {
        repliesCount++;
        greetings.push(GreetingMessage(newGreeting, msg.sender));
    }
    
    function kill() onlyOwner public {
        selfdestruct(owner); 
    }
 
}
  • How we can inspect only by transaction hash which is not existing in etherscan? Attach here all of your js code where you are firing the transactions, also attach the code of the smart contract. – Miroslav Nedelchev Mar 4 at 5:09
  • Which network are you using? main ir testnet. Does the account have enough ether to pay transaction fees? Did you set the gas price to a reasonable value? web3 only waits a transaction to be mined for 50 blocks (approx 750 seconds). – Ismael Mar 4 at 8:34
  • I use Rinkeby network, also have 50+ ether on the account. gas: 500000 gasPrice: 1 gwei. Let me update the question then. – gomozor Mar 4 at 9:02
  • 1
    If you want to execute a function with call, why do you send a transaction ? – Florian Castelain Mar 4 at 9:21
  • I assumed it needs to because the method needs input parameter. – gomozor Mar 4 at 10:01
0

Hi all,

I appreciate the comments and attention you gave. I figured out the solution here and wanted to share my inference from the struggle.

  1. Making a transaction for a call sounded unnecessary because it has view state modifier, which makes the function only callable and states this function does not require any gas essentially so I made 1 mistake here...

  2. getGreeting() should also return only if the msg.sender is the owner of the contract, that is why I wait that much.

Regards...

| 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.