0

I'm learning Solidity and the deployment script says something like this,

var Storage = artifacts.require("./Storage.sol");
var InfoManager = artifacts.require("./InfoManager.sol");

    module.exports = function(deployer) {

        // Deploy the Storage contract
        deployer.deploy(Storage)
            // Wait until the storage contract is deployed
            .then(() => Storage.deployed())
            // Deploy the InfoManager contract, while passing the address of the
            // Storage contract
            .then(() => deployer.deploy(InfoManager, Storage.address));
    }

And I can't seem to Google the right arrow character "=>".

vyap56
  • 172
  • 7
  • we call this in javascript fat arrow functions, unlike callback in anonymous operation you have access inside the context of the parent (this) – wamba kevin Mar 03 '19 at 12:15
  • [MDN Arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) – t.niese Mar 03 '19 at 12:21

2 Answers2

1

() => is an arrow function in Javascript.

Definition

An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords. Arrow function expressions are ill suited as methods, and they cannot be used as constructors.

Read more about arrow functions

.then()

Definition:

The then() method returns a Promise. It takes up to two arguments: callback functions for the success and failure cases of the Promise.

Read more about Promise.prototype.then()

What is happening is that when the deployer.deploy(Storage) promise has resolved, you are then executing the function storage.deployed() as a callback function.

amyloula
  • 1,496
  • 2
  • 15
  • 26
0

The right arrow (=>) indicates an arrow function, very similar to the anonymous function (function() { ...body }) you may be more familiar with.

They behave very similar, except for that while anonymous functions change what this points to, arrow functions do not. In this example it would not have mattered which had been used, but the arrow function is often favoured regardless due to it allowing for simpler code.

Newbyte
  • 1,154
  • 3
  • 15
  • 30