Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I've updated the Inbox section for new people doing the course. #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions inbox/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RPC_URL="https://rinkeby.infura.io/v3/YOUR_API_KEY"
PRIVATE_KEY="YOUR_PRIVATE_KEY_STARTING_WITH_0x"
ACCOUNT="YOUR_ACCOUNT"
7 changes: 7 additions & 0 deletions inbox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
First of all, open a terminal at the root folder and run "npm i".

BEFORE running the tests or using the command "node compile":
Open the ".env" file and replace the values:
* RPC_URL - Get it for the testnet you want to use from your infura.io account.
* ACCOUNT - Open Metamask and by clicking on e.g. "Account 1", you will copy the value to the clipboard.
* PRIVATE_KEY - Open Metamask, click the 3 dots next to "Account 1" -> Account details -> Export Private Key. You will get your key after typing your password. Paste it in this field in .env but prefix the copied value with "0x", e.g. "0xbe1e21dasd21ds...."
22 changes: 20 additions & 2 deletions inbox/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ const fs = require('fs');
const solc = require('solc');

const inboxPath = path.resolve(__dirname, 'contracts', 'Inbox.sol');
const source = fs.readFileSync(inboxPath, 'utf8');

module.exports = solc.compile(source, 1).contracts[':Inbox'];
var input = {
language: 'Solidity',
sources: {
'Inbox.sol': {
content: fs.readFileSync(inboxPath, 'utf8')
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
};

var output = JSON.parse(solc.compile(JSON.stringify(input)));
//console.log(output.contracts['Inbox.sol']['Inbox'].abi);
//console.log(output.contracts['Inbox.sol']['Inbox']['evm'].bytecode); to get bytecode
module.exports = output.contracts['Inbox.sol']['Inbox'];
12 changes: 7 additions & 5 deletions inbox/contracts/Inbox.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
pragma solidity ^0.4.17;
// SPDX-License-Identifier: CPL-1.0

pragma solidity 0.8.0;

contract Inbox {
string public message;

function Inbox(string initialMessage) public {
constructor (string memory initialMessage) {
message = initialMessage;
}

function setMessage(string newMessage) public {
function setMessage (string calldata newMessage) public {
message = newMessage;
}
}
}
27 changes: 13 additions & 14 deletions inbox/deploy.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
const HDWalletProvider = require('truffle-hdwallet-provider');
require('dotenv').config()
const HDWalletProvider = require('@truffle/hdwallet-provider')
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');
const abi = require('./compile').abi; // the contract interface aka ABI
const bytecode = require('./compile').evm.bytecode.object;

const provider = new HDWalletProvider(
'call glow acoustic vintage front ring trade assist shuffle mimic volume reject',
'https://rinkeby.infura.io/orDImgKRzwNrVCDrAk5Q'
);
const provider = new HDWalletProvider(process.env.PRIVATE_KEY, process.env.RPC_URL)
const web3 = new Web3(provider);

const deploy = async () => {
const accounts = await web3.eth.getAccounts();
const accounts = await web3.eth.getAccounts();
console.log('Attempting to deploy from account', accounts[0]);

console.log('Attempting to deploy from account', accounts[0]);
const result = await new web3.eth.Contract(abi)
.deploy({data: bytecode, arguments: ['Hi there!']})
.send({from: accounts[0]});

const result = await new web3.eth.Contract(JSON.parse(interface))
.deploy({ data: bytecode, arguments: ['Hi there!'] })
.send({ gas: '1000000', from: accounts[0] });

console.log('Contract deployed to', result.options.address);
console.log('Contract deployed to: ', result.options.address);
};
deploy();

deploy();
Loading