Hello… I’ve completed the Hello World project in Remix IDE … … … and now I’m thinking about writing a Front End for it. . . Is this possible ? surely. I’ve setup a localhost environment. Is anyone available to discuss this ?
Thanks,
Hello… I’ve completed the Hello World project in Remix IDE … … … and now I’m thinking about writing a Front End for it. . . Is this possible ? surely. I’ve setup a localhost environment. Is anyone available to discuss this ?
Thanks,
Invalid JSON RPC response: "Cannot POST /\n"
Are you running the web3 code to interact with the smartcontract at the same index?
What software are you using?
Ultimately, the problem was with my Web3 Provider. I found this as an example and it works.
( I don’t fully understand it yet. )
const web3 = new Web3(Web3.givenProvider);
I’m using Remix for the contract and localhost for the front end.
@bhaun
Amazing to see you solve the problem.
Basically, you are using web3 to create an instance of the givenProvider
that is Network (mainnet, Ropsten, Kovan, etc.).
This is the ideal sample code you could use for your front-end web3 connection henceforth.
create main.js and add below
var web3 = new Web3(Web3.givenProvider);
var contractInstance;
var account;
$(document).ready(function() {
window.ethereum.enable().then(function(accounts){
account = accounts[0];
contractInstance = new web3.eth.Contract(window.abi, "your contract address", {from: accounts[0]});
});
});
Create an abi.js
file separately to add contract ABI.
Loan both files in your HTML.
Thanks… does the abi.js file have a variable inside it, or is it somehow automatically bound to window.abi ?
This is the sample ABI inside the abi.js
file.
Then we access the abi using the window
as you mentioned. It is not automatically bound
var abi = [
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "name",
"type": "string"
},
{
"indexed": false,
"internalType": "bool",
"name": "senior",
"type": "bool"
}
],
"name": "personCreated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "name",
"type": "string"
},
{
"indexed": false,
"internalType": "bool",
"name": "senior",
"type": "bool"
},
{
"indexed": false,
"internalType": "address",
"name": "deletedBy",
"type": "address"
}
]
thanks for your help