Smart contract development


Smart contract development

Combo allows developers to build projects using the same programming languages and tools used to build on Ethereum

The way you deploy contracts and interact with them on Combo is almost identical to the way you do it with L1 BNB Smart Chain.

Solidity support

Please read this sectionopen in new window of the docs if your project uses libraries.

Development stacks

  • Hardhat
  • Remix
  • Truffle
  • Waffle

Hardhat

  1. In Hardhatopen in new window you use a configuration similar to this.
import { HardhatUserConfig } from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';

const config: HardhatUserConfig = {
  solidity: {
    version: "0.8.19",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      },
    }
  },
  networks: {
    hardhat: {},
    combo: {
      url: "https://test-rpc.combonetwork.io",
      accounts: ["privatekey"],
    },
    local: {
      url: 'http://127.0.0.1:8545',
    },
  },
};

export default config;
  1. Compiling your contracts
  • To compile your contracts in your Hardhat project, use the built-in compile task:
$ npx hardhat compile
Compiling...
Compiled 1 contract successfully
  • The compiled artifacts will be saved in the artifacts/ directory by default, or whatever your configured artifacts path is. Look at the paths configuration section to learn how to change it. This directory will be created if it doesn't exist. After the initial compilation, Hardhat will try to do the least amount of work possible the next time you compile. For example, if you didn't change any files since the last compilation, nothing will be compiled: $ npx hardhat compile
  • If you only modified one file, only that file and others affected by it will be recompiled.
  • To force a compilation you can use the --force argument, or run npx hardhat clean to clear the cache and delete the artifacts.
  1. Deploying your contracts
  • To deploy a contract from the Hardhat console:
Greeter = await ethers.getContractFactory("Greeter")
greeter = await Greeter.deploy("Greeter from hardhat")
console.log(`Contract address: ${greeter.address}`)
await greeter.greet()
  1. Greeter interaction
  • Connect to the Greeter contract:
Greeter = await ethers.getContractFactory("Greeter")
atGreeter = await Greeter.attach(greeter.address)
  • Read information from the contract:
await atGreeter.greet()
  • Submit a transaction, wait for it to be processed, and see that it affected the state.
tx = await atGreeter.setGreeting(`Hardhat: Hello ${new Date()}`)
rcpt = await tx.wait()  
await atGreeter.greet()

Truffle

  1. In Truffleopen in new window you use a configuration similar to this one.
module.exports = {
  networks: {
    "combo": {
      provider: () => new HDWalletProvider(
         "MNEMONIC",
         "https://test-rpc.combonetwork.io"),
      network_id: 91715,
      gas: 1e6
   },
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.8.19",
      settings: {          
       optimizer: {
         enabled: false,
         runs: 200
       }
      }
    }
  },
};

Put the MNEMONIC for an account on Combo here

MNEMONIC=test test test test test test test test test test test junk
  1. Compiling your contracts Compile the contract and run the console.
truffle compile

3.Deploying your contracts You deploy a new contract from the console.

greeter = await Greeter.new("Greeter from Truffle")

Wait a few seconds for the deployment to actually happen.

console.log(`Contract address: ${greeter.address}`)
await greeter.greet()
  1. Greeter interaction
  • Connect to the Greeter contact.
atGreeter = await Greeter.at(greeter.address)
  • Read information from the contact.
await atGreeter.greet()
  • Submit a transaction.
tx = await atGreeter.setGreeting(`Truffle: Hello ${new Date()}`)
  • Wait a few seconds for the transaction to be processed.s See that the greeting has changed.
atGreeter.greet()

Remix

  1. In Remixopen in new window you access Optimism through your own wallet.

    • Add Combo Testnet to your wallet. The easiest way to do this is to use bnbchainlistopen in new window.

    • Log on with your wallet to Combo Testnet.

    • Browse to Remixopen in new window.

    • Click the compiler icon.

    • Select the Environment Injected Provider - MetaMask.

    • Accept the connection in the wallet.

    • Click Deploy.

    • Confirm the transaction in the wallet.

  2. Storage interaction

  • Connect to the Storage contact has deployed.

  • Expand the contract to see you can interact with it.

  • Click retrieve and expand the transaction result in the console (bottom right).

  • Type a num (1024) and then click store. Approve the transaction in your wallet.

  • See the results on the console and then click retrieve again to see the num changed (see it under the store button).