avatarLipika Sahu

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3786

Abstract

arison operators, and bitwise operators on this type too.</p><p id="c4da">It’s important to note that there is another type, called <code>bytes</code> which is different from the above in that it is a dynamically sized array, and not a value type but a reference type. It is basically shorthand for <code>byte[]</code>.</p><p id="ad39">When you can limit the length of your data to a predefined amount of bytes, it is always good practice to use some of <code>bytes1</code> to <code>bytes32</code> because it is much cheaper.</p><h2 id="0118">Enums</h2><p id="aea7"><b>Enums</b> in Solidity are a way to create user-defined types. Enums are explicitly convertible to integer types, but not implicitly. Enum values are numbered in the order they are defined, starting from 0.</p><p id="ed00">Enums are not part of the ABI (Application Binary Interface — more on this in a later lesson, but it’s basically how you encode Solidity code for the Ethereum Virtual Machine, and how you get data back). This means that if your function returns an <code>enum</code> for example, it will be automatically converted to a <code>uint8</code> behind the scenes. The integer returned is just large enough to hold all enum values. With more values, the size gets increased too (<code>uint16</code> and up).</p><p id="cdb6">The below code, taken from the <a href="https://docs.soliditylang.org/en/v0.4.24/index.html">Solidity docs</a>, defines an enum with four possible values, creates a variable of that enum named <code>choice</code> and a constant called <code>defaultChoice</code>that will hold a default value.</p><div id="cf29"><pre><span class="hljs-keyword">enum</span> <span class="hljs-title class_">ActionChoices</span> { GoLeft, GoRight, GoStraight, SitStill } ActionChoices choice; ActionChoices <span class="hljs-type">constant</span> <span class="hljs-variable">defaultChoice</span> <span class="hljs-operator">=</span> ActionChoices.GoStraight;</pre></div><p id="66a9">Now we can define some functions to interact with our <code>enum</code>.</p><div id="c0bb"><pre><span class="hljs-title function_"><span class="hljs-keyword">function</span> <span class="hljs-title">setGoStraight</span></span>() <span class="hljs-keyword">public</span> { choice = ActionChoices.GoStraight; }

<span class="hljs-title function_"><span class="hljs-keyword">function</span> <span class="hljs-title">setChoice</span></span>(ActionChoices <span class="hljs-keyword">new</span><span class="hljs-type">Choice</span>) <span class="hljs-keyword">public</span> { choice = <span class="hljs-keyword">new</span><span class="hljs-type">Choice</span>; }</pre></div><p id="6bc2">The first one simply sets the <code>choice</code> to <code>GoStraight</code> while the second one sets it to the choice that the caller passes into the function. As we can see after deployment, the <code>setChoice</code> function expects a <code>uint8</code> value, which corresponds to the <code>enum</code> value declared at that number.</p><figure id="e997"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*1pKNPVy4UUBCSLi2-SIckg.png"><figcaption>Testing enums in Remix</figcaption></figure><p id="7917">If we want to get the value of <code>choice</code> and <code>defaultChoice</code>, we can define the following functions:</p><div id="1f02"><pre><span class="hljs-keyword">function</span> <span class="hljs-title">getChoice</span>() public view returns (ActionChoices) { <span class="hljs-keyword">return</span> <span class="hljs-type">choice</span>; }</pre></div><div id="43e7"><pre><span class="hljs-function">function <span class="hljs-title">getDefaultChoice</span>() <span class="hljs-keyword">public</span> pure <span class="hljs-title">returns</span> (<span class="hljs-params"><span class=

Options

"hljs-built_in">uint</span></span>)</span> { <span class="hljs-keyword">return</span> <span class="hljs-built_in">uint</span>(defaultChoice); }</pre></div><p id="c2f2">As we can see if we try this out in Remix, the first function returns a <code>uint8</code> while the second returns a <code>uint256</code>.</p><figure id="e514"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*jmaOFb9GhXz7FWC4ONMa_A.png"><figcaption>Testing enums in Remix</figcaption></figure><h2 id="3c7c">Fixed point numbers</h2><p id="2ecc"><b>Fixed point numbers </b>represent fractional numbers by storing a fixed number of digits of their fractional part. No matter how large or small the fractional part is, it will always use the same number of bits.</p><p id="cdcd" type="7">Fixed point numbers are not fully supported by Solidity yet. They can be declared, but cannot be assigned to or from.</p><p id="f872">We can differentiate between signed fixed point numbers, declared with the <code>fixed</code> keyword, and unsigned fixed point numbers, declared with the <code>ufixed</code> keyword.</p><p id="3c1c">It can also be declared as <code>fixedMxN</code> or <code>ufixedMxN</code> where <code>M</code> represents the number of bits the type takes, and <code>N</code> represents the number of decimal points. <code>M</code> has to be divisible by 8 and a number between 8 and 256. <code>N</code> has to be a number between 0 and 80.</p><p id="96e1">They function with the following operators:</p><ul><li>Comparisons: <code><=</code>, <code><</code>, <code>==</code>, <code>!=</code>, <code>>=</code>, <code>></code> (evaluate to <code>bool</code>)</li><li>Arithmetic operators: <code>+</code>, <code>-</code>, unary <code>-</code>, unary <code>+</code>, <code>*</code>, <code>/</code>, <code>%</code> (remainder)</li></ul><h2 id="09b7">Conclusion</h2><p id="bd3a">In this lesson, we looked at what value types are available in Solidity and how each one works.</p><p id="28de">Thank you for staying with us till the end. If you enjoyed reading this piece please keep in touch and follow Solidify to keep up with our lessons on Solidity. In the upcoming articles, we will deep dive into the intricacies of the language, progressing from beginner to advanced level.</p><p id="067c">If you are new to Solidity, check out the previous lessons about setting up a local development environment and writing your first smart contract.</p><div id="6b76" class="link-block"> <a href="https://readmedium.com/how-to-setup-your-local-solidity-development-environment-c4c8195810f3"> <div> <div> <h2>How to Setup Your Local Solidity Development Environment</h2> <div><h3>Get started with smart contract development</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*HHko-o9m1sVngmTeRVYgKA.jpeg)"></div> </div> </div> </a> </div><div id="3ad1" class="link-block"> <a href="https://readmedium.com/lesson-1-your-first-solidity-smart-contract-1ba7e641f9a3"> <div> <div> <h2>Lesson 1: Your First Solidity Smart Contract</h2> <div><h3>In the previous lesson, we looked at how to set up your local Solidity development environment. Here we will continue…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*7r7HSYkbn73NrmR_skvh5w.jpeg)"></div> </div> </div> </a> </div></article></body>

on writing better

1 Year, 2 Books, 3 Platforms, ~4M Views Later — My 7 (Undying) Codes of Writing That Worked

#4 Your maximum effort => audience’s minimum effort

Photo by Vinicius Wiesehofer: https://www.pexels.com/photo/closeup-photo-of-smiling-woman-wearing-blue-denim-jacket-1130626/

I have never used so many numbers in my headline…

Moreover, I am really shy and not comfortable with boastful numbers.

So, I am feeling like a fish out of water here…putting those numbers on the board. But my sole purpose is to tell you that however bleak it may look now, it’s doable.

Because if you had told me of something like this a year back, I would have choked up laughing.

Or given you my typical poker face — the one I give to meaningless talks.

Trust me, I started writing with absolutely no knowledge of the:

Immense power of the internet, Earning potential of penning thoughts, Cumulative force of building something consistently, Impact of mere words.

And yet, it all happened.

Sometimes I feel like it’s all a lucky stroke. Or maybe divine intervention.

But then it’s not. However rosy the picture might look today, it was not a seamless performance each time.

Sometimes…many times…it was a shitshow .

So, when I say ‘worked for me’, you must understand that it’s the culmination of permutations & combinations of N things that have clicked & 100xN that haven’t.

1. Being comfortable with ‘FREE’ before making money.

I always wondered why many writers gave away things for free. I really felt it was extremely foolish of them…and the joke was on me, I know.

FREE is the most expensive word.

It creates an illusion that the receiver is benefiting more. It (already) creates a positive association with source. It catches the attention in the shortest time. The hesitation meter immediately drops. Encourages one to join the ‘herd’. It lets the guard down.

The fastest way to build an audience.

Use FREE to build an audience and then start selling.

2. You are worth the audience you own.

And not the followers you have on a platform.

It’s exactly like the difference between doing a job and your own setup. No matter how successful you are in a job, you are bound by its rules. With your own thing, it’s all yours to take.

The only way to own your audience — build an email list.

I was a tad late to this party. I recently started my newsletter and I often beat myself for not starting earlier.

Remember FREE? That’s the most popular way to own your audience. Collaborating, consistently showing up with value-driven content, interacting, engaging on social platforms, incentivizing, etc. are some other ways to build your community.

Start early and invest in your writing net worth — catch them young.

3. It’s 1% writing; 99% editing.

My daughter loves baking but hates cleaning up after that. How she would love it if she could skip that part…well, not in my kitchen.

And if you are someone like my daughter, know that writing is all about cleaning up.

It’s perfectly okay to write garbage — as long as you edit brilliantly.

C. J. Cherryh

It is not about writing at all. It’s all about editing — mercilessly. When I edit my work, I feel like combing my long hair after a scarf-lees bike ride (you will know only if you have had one…it’s utterly messy)

Painfully detangling each knot, trying to save the strands from falling. And with every run of the comb, it’s a tad better.

Writing is all about detangling those knots in your story. Master the art of editing and you have mastered writing.

4. Your maximum effort => audience’s minimum effort.

Understand your audience.

— Extremely lazy — Excessively restless — Overly selfish — Too easily bored.

If you crack this code, you are sorted.

  • For laziness:- do the maximum work for your audience and make everything easily digestible for them. Bite-size.
  • For restlessness:- come to the point quickly (or you lose them around the next corner)
  • For selfishness: make everything about ‘what’s in it for them’.
  • For the boringness:- entertain, entertain, entertain. Even if you are writing about death, be lively. And throw in some stories (coming up next).

5. Retracing granny’s footsteps.

My grandma could turn a drab incident like a scheduled power cut (we used to have many) into a nail-biting thriller. She knew how to hold the attention of her audience of children.

Decades later, I am using her finesse to hold my audience’s attention.

The art of storytelling — everything sells, as long as you have the right story to sell it.

And you don’t have to be a Rowling or a Christie to tell stories.

— Sprinkle some drama, — Talk about yourself, — Share personal lessons learned, — Paint an imagination, — Throw in some incidents, — Success stories (yay!), and — Failure stories (even better).

They are all stories.

Tuck them (the audience) in, and tell a story — they are all ears for that.

6. ‘YOU’ is the secret sauce.

No typo there. Hear me out.

Every story/idea, no matter how many times it has been talked about, will stand out if it has one distinct ingredient — YOU.

Your job, as a writer, is not about bringing new (ideas) to the table every time. It’s about telling it in your distinct way.

And trust me, losing this originality is as easy as counting the number of houses in a one-house village. Correct…that’s 1.

The thing is, in the quest to learn/grow/explore, you read some of that viral piece, that viral writer, that boosted story — and your mind starts picking up pieces.

And before you know it, you have cooked a funny concoction of it all.

Your original spark, that carefree spirit, that tangy but unblemished taste is missing in your writing. DON’T lose it.

Mummify your original voice.

Because your unique perspective, experiences, and emotions infuse your work with authenticity, setting it apart from others.

7. It’s like growing bamboo.

The Chinese bamboo.

For almost 4 years you nurture and water the seeds, but nothing comes out. But in the fifth year, it appears — the sprout. And then, boy, does it grow!?

I am not saying that for 4 years your writing will yield no results. But for some time (enough to test your patience), you might see no visible results.

Giving you ample reasons to throw the towel.

Your every cell will scream — nothing is happening; it’s a waste of time. But, hold on. Nothing is visible doesn’t mean that nothing is working.

It might look slothishly slow, but it’s happening. Hold on till it sprouts.

Finally…

I can add so many more, but these are the ones that hit the nail the hardest.

  1. Use FREE to pave the (shortest) path to $$$.
  2. You own your audience only if you have their address(email). Start hoarding them.
  3. Your crappy writing doesn’t matter as long as you can edit okay.
  4. Learn to sweat so that your reader doesn’t. Like duck soup — light, easy-to-eat, healthy, & lip-smacking tasty.
  5. A story is your way into their head — tell one and you have all their attention.
  6. Your writing voice is your most precious possession. Never lose it.
  7. Writing isn’t the toughest part — it’s sticking around long enough is where most people fail.

Need some more help in writing? Find it here.

Or… you can also do this…

Join me @The Write Shot, a weekly inspireletter (no, I don’t call it a newsletter) that nudges struggling writers to do more and keep their (writing) spirits high.

Writing
Blog
Business
Entrepreneurship
Startup
Recommended from ReadMedium