• Baseball
  • Basketball
  • Esports
  • Football
  • Golf
  • MMA
  • NFL
  • Tennis
  • WWE
Wedding Blog
  • Baseball
  • Basketball
  • Esports
  • Football
  • Golf
  • MMA
  • NFL
  • Tennis
  • WWE
Wedding Blog
No Result
View All Result

Marcus Smart Contract Security: Best Practices to Follow

reeccw@2cSa by reeccw@2cSa
04/11/2025
in Basketball
Marcus Smart Contract Security: Best Practices to Follow

Okay, so here’s the deal. Today, I’m diving into my experience with building a “marcus smart contract.” It was a bit of a rollercoaster, so buckle up!

Marcus Smart Contract Security: Best Practices to Follow

First off, I had this idea bouncing around in my head. I wanted to create a simple smart contract. I figured, how hard could it be, right? Famous last words.

So, I jumped straight into Remix, the online Solidity IDE. It’s pretty handy for quick prototyping. I started sketching out the basic structure of my contract. I wanted it to have a function to set a value, and another function to read that value. Classic stuff.

I started by declaring the state variable that was going to hold my data. Something super simple, like a uint256 called myValue. Then, I wrote the setValue function. This was supposed to take a uint256 as input and update myValue.

solidity

pragma solidity ^0.8.0;

Marcus Smart Contract Security: Best Practices to Follow

contract MarcusContract {

uint256 public myValue;

function setValue(uint256 _newValue) public {

myValue = _newValue;

function getValue() public view returns (uint256) {

Marcus Smart Contract Security: Best Practices to Follow

return myValue;

I deployed it to the Remix VM. Tried calling the setValue function with different numbers. Checked if the getValue function returned the correct value. Everything seemed fine and dandy.

Next, I decided to get a little fancy. I wanted to add an event that would be emitted whenever the value was changed. Just for the heck of it. I added an event declaration and an emit statement inside the setValue function.

solidity

Marcus Smart Contract Security: Best Practices to Follow

pragma solidity ^0.8.0;

contract MarcusContract {

uint256 public myValue;

event ValueChanged(uint256 newValue);

function setValue(uint256 _newValue) public {

Marcus Smart Contract Security: Best Practices to Follow

myValue = _newValue;

emit ValueChanged(_newValue);

function getValue() public view returns (uint256) {

return myValue;

Marcus Smart Contract Security: Best Practices to Follow

Redeployed, tested again. Yep, events were firing as expected. I patted myself on the back at this point.

Then I thought about security. I mean, anyone could call setValue and change the value. That’s no good. I wanted only the contract creator to be able to modify it.

So, I added a constructor to store the address of the deployer and a require statement in the setValue function to check if the caller is the owner.

solidity

pragma solidity ^0.8.0;

Marcus Smart Contract Security: Best Practices to Follow

contract MarcusContract {

uint256 public myValue;

address public owner;

event ValueChanged(uint256 newValue);

constructor() {

Marcus Smart Contract Security: Best Practices to Follow

owner = *;

function setValue(uint256 _newValue) public {

require(* == owner, “Only the owner can set the value.”);

myValue = _newValue;

emit ValueChanged(_newValue);

Marcus Smart Contract Security: Best Practices to Follow

function getValue() public view returns (uint256) {

return myValue;

Deployed it to a testnet, tried calling setValue from a different account. BAM! “Only the owner can set the value.” message. Success!

Now, for the final touch, I wanted to make the contract a bit more… interesting. I decided to add a function that would multiply myValue by a given factor.

Marcus Smart Contract Security: Best Practices to Follow

solidity

pragma solidity ^0.8.0;

contract MarcusContract {

uint256 public myValue;

address public owner;

Marcus Smart Contract Security: Best Practices to Follow

event ValueChanged(uint256 newValue);

constructor() {

owner = *;

function setValue(uint256 _newValue) public {

require(* == owner, “Only the owner can set the value.”);

Marcus Smart Contract Security: Best Practices to Follow

myValue = _newValue;

emit ValueChanged(_newValue);

function getValue() public view returns (uint256) {

return myValue;

function multiplyValue(uint256 _factor) public {

Marcus Smart Contract Security: Best Practices to Follow

require(* == owner, “Only the owner can multiply the value.”);

myValue = myValue _factor;

emit ValueChanged(myValue);

Deployed it again. Tried multiplying the value by different numbers. Worked like a charm. It was cool seeing the value change and the events firing.

It wasn’t super complex, but it was a great exercise. I touched on basic state variables, functions, events, modifiers, and even a little bit of security. It’s all about taking small steps and building from there.

ShareTweetPin
Previous Post

Barry Switzer Jerry Jones: The Untold Story Revealed

Next Post

Zhang vs Eubanks Prediction: Keys to Victory Explored

Related Posts

Cade Klubnik Injury: How Long Will He Be Out For?
Football

Cade Klubnik Injury: How Long Will He Be Out For?

by reeccw@2cSa
04/17/2025

Alright, let me tell you about this whole “Cade Klubnik injury” thing I dove into. I was just chilling, scrolling...

Read more
Rublev vs Broady: Dont Miss This Unforgettable Battle!

Rublev vs Broady: Dont Miss This Unforgettable Battle!

04/17/2025
Shapovalov vs Jarry: What Makes This Rivalry So Intense?

Shapovalov vs Jarry: What Makes This Rivalry So Intense?

04/17/2025

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

About

Hi there! Welcome to the Wedding blog; a journal about marriage and life. Stay a while and do say hello if you please!

No Result
View All Result

Recently Added

Cade Klubnik Injury: How Long Will He Be Out For?

Cade Klubnik Injury: How Long Will He Be Out For?

04/17/2025
Rublev vs Broady: Dont Miss This Unforgettable Battle!

Rublev vs Broady: Dont Miss This Unforgettable Battle!

04/17/2025
Shapovalov vs Jarry: What Makes This Rivalry So Intense?

Shapovalov vs Jarry: What Makes This Rivalry So Intense?

04/17/2025

Popular Posts

  • Who is the Green Shirt Guy in WWE? The Story Behind the Iconic Superfan

    Who is the Green Shirt Guy in WWE? The Story Behind the Iconic Superfan

    0 shares
    Share 0 Tweet 0
  • Julianna Brooks Leaks: Latest Exclusive Content and Updates

    0 shares
    Share 0 Tweet 0
  • Remembering Melissa Johnson: The 1996 Wimbledon Streaker Who Interrupted History

    0 shares
    Share 0 Tweet 0
  • Is Jim Schlossnagle Married? The Truth Behind His Relationship Status

    0 shares
    Share 0 Tweet 0
  • Brandon Hyde Salary Revealed: Is the Orioles Manager Paid Fairly in 2024?

    0 shares
    Share 0 Tweet 0
  • Baseball
  • Basketball
  • Esports
  • Football
  • Golf
  • MMA
  • NFL
  • Tennis
  • WWE

© Copyright 2018 JNews - Premium WordPress Theme.

No Result
View All Result
  • Baseball
  • Basketball
  • Esports
  • Football
  • Golf
  • MMA
  • NFL
  • Tennis
  • WWE

© 2018 JNews - Theme by Jegtheme.