fbpx

Understanding Truffle variable injection magic in test files

Julien Klepatch

In Truffle, when you write tests, you can use ‘artifacts’ and ‘web3’ objects, without defining these names:

const MyContract = artifacts.require('MyContract'); //artifacts was never defined before !
const web3 = new Web3('http://localhost:8545'); //same thing for Web3!

How is it possible? this is not valid Javascript! Well, this is what Truffle calls “variable injection”, and to understand how this work, watch this video to have the answer and have a peek at Truffle internals:

0 Comments

Leave a Reply

More great articles

Syntax vs runtime vs logic errors in solidity

A lot of people are confused about debugging in general and don't know the difference between a syntax error and…

Read Story

Testing integers in smart contract with Truffle and bn.js (Big Number)

In Solidity smart contract, you might have to deal with huge numbers, especially when doing financial transfers. Don't forget that…

Read Story

ToDo List Ethereum Dapp (Intro)

Last updated: November 2018. This tutorial series will teach you how to build a ToDo List Dapp on Ethereum. It…

Read Story

Never miss a minute

Get great content to your inbox every week. No spam.
[contact-form-7 id="6" title="Footer CTA Subscribe Form"]
Arrow-up