Home KEVM IELE Roadmap Support

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 kevm 	

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 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() 
Enter password:

The newAccount command asks your password, and returns your new account address.

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 smart contracts

To deploy your smart contracts on the KEVM testnet you will need to compile to KEVM (K - Ethereum virtual machine) bytecode. You can compile the bytecode directly with using isloc, or using an IDE (Integrated development environment) such as Remix or similar.

Disclaimer: Remix is just one IDE that you can use to compile the bytecode. There are other IDEs that also perform this function. We have included instructions on using Remix as an example

Compiling with Remix IDE

The easiest way to compile your smart contract to use Remix Write your code in the Editor window Press [Start to compile] When the smart contract is compiled click [Details]

Check the details of the transaction Copy the Runtime Bytecode json

Paste it in mallet to an object:

mallet> runtimeBytecode = {"object": "60806040523480...."}
mallet> myContract = runtimeBytecode.object

Now that your smart contract is in the my_contract variable jump to the ‘Deploying contracts’ section.

Compiling with ‘isloc’ (command line)

You can also compile your smart contract using only commandline tools. In that regard you will need to install the ‘solc’ (soliditiy to KEVM compiler) in you can compile smart contracts directly from your terminal:

# from your terminal NOT inside mallet
solc --bin --abi myContract.sol > myContract.bin

With your compiled code, now you can read it and deploy it from mallet

// import the fs module from Node.js
mallet> fs = require('fs')

// read the contents of the file
mallet> myContract = fs.readFileSync('myContract.bin', 'utf8')

Deploying smart contracts

Now that you have the bytecode either from solc or from Remix, the next step is simply to deploy it:

// prepare the transaction to deploy the contract
mallet> tx = {
// gas limit, mandatory
    gas: 470000,
// the variable with our smart contract binary                      
    data: myContract
};

//deploy the smart contract
mallet> deploymentHash = sendTransaction(tx)
Enter password:

//you will get back the tx hash on which it was deployed. 
'0x........'

View receipt

You can view details with the following command:

mallet> getReceipt(deploymentHash)

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

mallet> myContractAddress = getReceipt(deploymentHash).contractAddress

Test your smart contract To test your contract:

mallet> sendTransaction({to: myContractAddress, 
    gas:, 
    arguments: args});

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