0
var Web3 = require('web3')

var url = 'https://rinkeby.infura.io/v3/cadc6b0dc5c54720b973b3720eab5584' 

var web3 = new Web3(url)




var RemixContract = new web3.eth.Contract([
    {
        "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"
    }
],'0x7Cad41DAc15e54051c387895541875B46932fa09',{from:'0x84809AC58F7476Ba7A6F8BF2C66896d0fa59F6f6'});


RemixContract.methods.setMessage("Again").send()

Here is my 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;
    }
}
0

1 Answer 1

0

This is not the way you can connect to infura. change this code

var url = 'https://rinkeby.infura.io/v3/cadc6b0dc5c54720b973b3720eab5584' 

var web3 = new Web3(url)

with this code

const url = new Web3.providers.HttpProvider(
    'https://rinkeby.infura.io/v3/cadc6b0dc5c54720b973b3720eab5584'
  );
web3 = new Web3(url);

Also you better update your solidity code to the latest.

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