0
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Deploy a Remix Contract</title>

    <link rel="stylesheet" type="text/css" href="main.css">

    <script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>
</head>

<body>
    <div>
        <h1>Ethereum Secret Messenger</h1>
        <hr>

        <label for="message">This site writes a secret message to the Ethereum
            blockchain!</label>
        <input id="userInput" type="text">

        <button type="button" id="setMessageButton" onclick="setMessage()">Set secret message</button>
    </div>

    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>

    <script>

        // Connect a the web3 provider
        if (typeof web3 !== 'undefined') {
            web3 = new Web3(web3.currentProvider);
        } else {
            web3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/v3/0f3d9f30356e48c7b048c0b6a6c8ceae"));
        }

        // Set a default account
        web3.eth.defaultAccount = web3.eth.accounts[0];
        var abi = [
    {
        "constant": false,
        "inputs": [
            {
                "name": "x",
                "type": "string"
            }
        ],
        "name": "setMessage",
        "outputs": [],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
    },
    {
        "constant": true,
        "inputs": [],
        "name": "getMessage",
        "outputs": [
            {
                "name": "",
                "type": "string"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    }
]
        // Get the contract address
        var RemixContract = new web3.eth.Contract(abi, '0x633566E3C7e08f660987719841F77c0faa85bFbF');

        const setMessage = ()=>{
            RemixContract.methods.setMessage(document.getElementById("userInput").value).send({from:'0x20f2E66DA9315D447b22059F154ed1E016d41369'});
            console.log(document.getElementById("userInput").value)
        }

    </script>
</body>

</html>

I am connecting to Rinkeby test blockchain using infura and deployed the below contract using remix and I injected my account using web3 with metamask.

Contract:

pragma solidity ^0.4.24;

contract Message {
    string myMessage;

    function setMessage(string x) public {
        myMessage = x;
    }

    function getMessage() public view returns (string) {
        return myMessage;
    }
}

when i send the message in my html file i get this error Uncaught (in promise) Error: Returned error: The method eth_sendTransaction does not exist/is not available

The code was working when i used in local blockchain by Ganache but when i transferred to Rinkeby i get this error please help guys

Please note that I am new to BlockChain and I just want to send a transaction containing only message using the function in the smart contract. Please tell me what to change in order for making it works.

4
  • Infura doesn't support eth.sendTransaction. You have to sign the transaction yourself and send them using eth.sendSignedTransaction. You can automate it using a provider that signs transactions like @truffle/hdwallet-provider or a wallet like metamask.
    – Ismael
    Oct 25, 2021 at 20:19
  • 1
    I am new to Blockchain, my purpose is to send a simple message to the blockchain, and I do not know where to use the eth.sendSignedTranscation, should I use it instead of send()?
    – нεx
    Oct 26, 2021 at 6:56
  • Metamask has changed the way it should be initialized. Check their documentation docs.metamask.io/guide/getting-started.html.
    – Ismael
    Oct 26, 2021 at 21:29
  • Hey @нεx did you able to resolve it?
    – Steven
    Jun 20, 2022 at 15:26

0

Your Answer

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

Browse other questions tagged or ask your own question.