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

Basic testing workflow with Truffle – Part 2

In this video, we will go through the whole process of test-driven-development (TDD) for Solidity smart contracts: writing the tests…

Read Story

Simple storage – Part II

In this video, we are going to finish our simple storage smart contract, which can set and get the value…

Read Story

Crud – Part I

We will start a CRUD smart contract in Solidity. Crud stands for Create, Read, Update and Delete, and represent a…

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