Follow every step in the course. but try to install the updated version of everything you see on that course. To install solc just type npm install solc
in the nodejs command prompt, this will install the latest version automatically ( you don't need to specify the version ).
You can also try uninstalling and reinstalling the solc by doing npm uninstall solc
first, then again install it by npm install solc
.
For the code part, these are the updated codes you need for the course.
Please just don't copy and paste, make sure you learn from the changes.
Inbox.sol:
pragma solidity ^0.6.6;
contract Inbox{
string public message;
constructor (string memory initialMessage) public{
message = initialMessage;
}
function setMessage(string memory newMessage) public{
message = newMessage;
}
}
Compile.js
const path = require('path');
const fs = require('fs');
const solc = require('solc');
const inboxpath = path.resolve(__dirname, 'Contracts', 'Inbox.sol');
const source = fs.readFileSync(inboxpath, 'UTF-8');
var input = {
language: 'Solidity',
sources: {
'Inbox.sol' : {
content: source
}
},
settings: {
outputSelection: {
'*': {
'*': [ '*' ]
}
}
}
};
var output = JSON.parse(solc.compile(JSON.stringify(input)));
exports.abi = output.contracts['Inbox.sol']['Inbox'].abi;
exports.bytecode = output.contracts['Inbox.sol']['Inbox'].evm.bytecode.object;
Deploy.js
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { abi, bytecode} = require('./compile');
const provider = new HDWalletProvider(
'Your mnemonic',
'https://rinkeby.infura.io/...'
);
const web3 = new Web3(provider);
const deploy = async () => {
const accounts = await web3.eth.getAccounts();
console.log('Attempting to deploy from account',accounts[0]);
const result = await new web3.eth.Contract(abi)
.deploy({data: '0x' + bytecode, arguments: ['Hi there']})
.send({from: accounts[0]});
console.log('contract deployed to', result.options.address);
}
deploy();
Please just don't copy and paste, make sure you learn from the changes.