Interact with smart contracts

The iotx.Contract class of Antenna makes it easy to interact with smart contracts on the IoTeX blockchain. When you create a new Contract object, just initialize it with the JSON interface (ABI) of the respective contract, and the Contract object will take care of converting all contract method calls into low-level ABI calls over RPC for you.

Need a full example? Check the integration test.

Compiling Solidity Code

Antenna SDK does not compile solidity code itself; however you can get the ABI and bytecode of your contract in one of the following options:

  • Option 1: use our IoTeX Studio web IDE to compile your smart contract and copy the ABI/Bytecode

  • Option 2: in Node.js, import and use the solc node package, as in the following example:

import solc from "solc";

const solidityFileString = `
pragma solidity ^0.4.16;

contract SimpleStorage {
   uint storedData;

   function set(uint x) public {
       storedData = x;

   function get() public view returns (uint) {
       return storedData;
const contractName = ":SimpleStorage";
const output = solc.compile(solidityFileString, 1);
const abi = JSON.parse(output.contracts[contractName].interface);
const bytecode = output.contracts[contractName].bytecode;

Deploying a Smart Contract

Once you get the ABI and bytecode from the step above, then you can deploy it by sending the deploy action to the IoTeX blockchain network.

import Antenna from "iotex-antenna";
import { toRau } from "iotex-antenna/lib/account/utils";

(async () => {
  const antenna = new Antenna("");

  const bytecode =

  const abi = `[
      constant: false,
      inputs: [{ name: "x", type: "uint256" }],
      name: "set",
      outputs: [],
      payable: false,
      stateMutability: "nonpayable",
      type: "function"
      constant: true,
      inputs: [],
      name: "get",
      outputs: [{ name: "", type: "uint256" }],
      payable: false,
      stateMutability: "view",
      type: "function"
      inputs: [{ name: "_x", type: "uint256" }],
      payable: false,
      stateMutability: "nonpayable",
      type: "constructor"

  const creator = antenna.iotx.accounts.privateKeyToAccount(

  const actionHash = await antenna.iotx.deployContract({
    from: creator.address,
    amount: "0",
    abi: abi,
    data: Buffer.from(bytecode, "hex"),
    gasPrice: toRau("1", "Qev"),
    gasLimit: "100000"

Once the action is broadcast, you can query it:

const receipt = await antenna.iotx.getReceiptByAction({
  actionHash: actionHash

Finally, once the action is minted, you can query the receipt

const receipt = await antenna.iotx.getReceiptByAction({
  actionHash: actionHash

Last updated