Filtered by

cardano logo

Mallet 2.0 tutorial


Once you have installed Mallet 2.0, follow the tutorial to:

  • connect to the testnet;
  • create accounts;
  • request tokens from the faucet;
  • compile a smart contract (only available for IELE testnet);
  • deploy it in the testnet;
  • execute a smart contract.

To run Mallet and connect to a testnet:

#connect to the IELE or KEVM testnet

$ ./mallet iele 	

This will open a session in the read-eval-print-loop (Repl) environment for Node.js. Mallet commands are imported automatically.

Everything typed in the Repl has to be valid JavaScript. Technically speaking, the commands are simply functions and properties of a Mallet object. However, we tend to refer to them as commands because that reflects how they are used.

Basic Commands

Create an account
mallet> myAccount = newAccount('password') 

The newAccount command takes one argument, which is your password.

This will return your new account:

0x*************

Note that we are assigning the return value of newAccount to a variable named myAccount so that we can refer to it later.

List existing accounts

mallet> listAccounts() 

Will return a list of all existing accounts.

Select an account

mallet> selectAccount(myAccount)

Get the balance of your account

mallet> getBalance()

If you don’t give any argument, this will return the balance of the selected account.

Request tokens from the faucet

mallet> requestFunds()

It may take a few minutes for the funds to be transferred.

Now that you have created and funded your account, you can compile and deploy smart contracts.

Compiling contracts

The ability to compile contracts is currently only supported for IELE. Both IELE assembly code and Solidity (using the Solidity to IELE compiler) contracts can be compiled. Both compilers are services of the testnet that Mallet connects to (no additional dependencies).

Compile a smart contract

mallet> iele.compile('../filename')

Mallet can work with .sol or .iele files. Keep in mind that Solidity files will take a two-step compilation:

  • Solidity to IELE -> IELE assembly, and
  • .iele will take a single step through IELE assembly.

You can compile multiple source contracts, you only need to compile the main file. You will get a bytecode that includes all files that are imported in your main contract.

Get bytecode

To get the bytecode needed to deploy your smart contract, you can assign its value to a variable so that you can refer to it.

mallet> myBytecode = iele.compile('../filename.extension').bytecode

Deploy

To deploy your smart contract, select the account created earlier and then call the iele.deployContract() command.

mallet> iele.deployContract ({gas: 1000000, value: 0, code: myBytecode , args: [optional constructor arguments]})

After typing your password your contract will be deployed.

View details

You can view details with the following command:

mallet> getReceipt()

To save your contract address, create a variable that takes the return value of getReceipt().

mallet> myContractAddress = getReceipt().contractAddress

Test your smart contract

To test your contract:

mallet> iele.contractCall({to: myContractAddress, gas:, args [optional arguments]})

Getting help

When running Mallet in the command-line interface, the help command can be useful. This opens the Readme file in your default web browser:

mallet> help()

Next navigation arrow