testdirectories that we require for this tutorial.
@truffle/hdwallet-provider, so we need to add it to the project. Let's add it as a development dependency:
truffle-config.js(just like HDWalletProvider, this section is from line 44 to line 48 in my file):
module.exports(you can place it below as well, just not within). We will call it
mandalaConfigand expect one argument to be passed to it. The argument passed to it is called the
endpointUrland specifies the RPC endpoint, to which the Truffle connects to. Copy the method into your
HDWalletProvidedthat we imported. We pass the mnemonic phrase, from which the accounts are derived, as well as the URL for the RPC endpoint of the desired network. You might have noticed that we haven't specified
mnemonicPhraseanywhere just yet. Let's do it. Above the
mandalaConfigadd the following mnemonic:
provider, let's move on to the other arguments:
network_idis the default network ID of the development Mandala network.
gasPriceis the default gas price for the local development Mandala network. Commented out section represents additional parameters of Acala EVM+.
gasis the current gas limit for transactions.
confirmationsare set to our discretion and we opted for the values above in this tutorial.
networkssection of the config using the
mandalaConfighelper. We do this by pasting the following two lines of code into it:
truffle-config.jsshould be uncommented:
0.8.9as this is the Solidity version we will be using in our example smart contract. To do this, line 98 needs to be uncommented and modified to:
Hello World!. To do that, we can use the Truffle built-in utility
HelloWorld.solfile with a skeleton smart contract within
contractsdirectory. First line of this smart contract should specify the exact version of Solidity we will be using, which is
helloWorldvariable and assign a
Hello World!value to it in the beginnging of the smart contract. We should also remove
publicvisibility setting of the
constructor()as the compiler ignores it anyway. Replace the body of the smart contract with the following code:
buildscript to the
package.json. To do this, we have to add
scriptssection to it. We will be using Truffle's compile functionality, so the
scriptssection should look like this:
yarn build, the
builddirectory is created and it contains the compiled smart contract.
testdirectory and we can start writing the tests. If you open the file, you can see that Truffle has already imported our smart contract in the first line of the file, so we can jump right into writing the tests. First we will create a
beforeaction. We require one globally available variable, called
instance, that will hold the information about the deployed smart contract. The
beforeaction in itself will just make sure that the smart contract is deployed. To add it, replace the current
itblock with the following code:
itblock, in which we will test that the right value is assigned to the
helloWorldvariable from the smart contract and assert that is is equal to
Hello World!. To do this, place the following two lines into the
package.json. One script will be used to test on a traditional local development network and one will be used to test on a Mandala local development network. We already added both into the
truffle-config.js. Add these lines to the
scriptssection of your
yarn test-mandala, depending on which network we want to use to run the tests.
yarn test, your tests should pass with the following output:
createto create a migration file:
migrationsfolder. First thing we need to do is import our smart contract into it. We do this with the following line of code at the top of the file:
deployeris ready. To do that, we need to modify the deployment function to be asynchronous. Replace the 3rd line of the migration with:
deployer, which is defined in the definition of the function. Additionally we will output the address of the deployed smart contract:
scriptssection in the
deploy-mandalascripts. To add these scripts to your project, place the following lines within
scriptssection of the
yarn deployscript should return the following output:
HelloWorld.solsmart contract, that can be compiled using
yarn build, and wrote a test for it, which can be run using
yarn test-mandala. Additionally we added the deploy script that can be run using