Deployment Scripts

Need a development SKALE Chain to deploy to? Checkout the Chaos Testnet endpoint.

Deploying to SKALE is similar to deploying to the Ethereum blockchain. There are a few changes you will need to make within your deployment scripts. When using these code samples, please be sure to modify the code appropriately before running anything in production!

You can share your own code sample by reaching out to the SKALE developer community on discord.

Use these deployment script examples to deploy your smart contracts onto your SKALE Chain.

  • Hardhat

  • Truffle

  • Node.js

  • Remix

  • thirdweb

Hardhat is a popular development environment for deploying and verifying smart contracts on EVM blockchains.

Hardhat is fully compatible with SKALE Network.

Overview

Below are the steps needed to update your hardhat configuration for deploying and verifying your SKALE chain.

  1. Make a .env` with SKALE configuration

  2. Update hardhat.config with dotenv variables

  3. Write or add a deploy script using ethers.js or web3.js

  4. Deploy with the --network skale flag

  5. Verify all dependencies for verification are installed

  6. Verify with returned contract address and any constructors- if any

Alternatively, you can use this preconfigured SKALE hardhat repository set for Chaos open testnet

CONFIGURATION

The code below shows how to configure hardhat with your private key and a SKALE RPC endpoint for SKALE Chaos open testnet.

  1. To deploy your smart contracts onto SKALE Chaos (or other SKALE chain ), you will need to write a script using ethers or web3.

    For much more information on hardhat configuration and deployment scripts visit: Hardhat’s Documentation.
  2. Copy or Configure your .env for SKALE Network:

    Env Config

    /* change file name from sample.env -> .env to enable setup to use dotenv */
    
    PRIVATE_KEY= (1)
    
    (2)
    SKALE_ENDPOINT=https://staging-v3.skalenodes.com/v1/staging-fast-active-bellatrix
    
    CHAIN_ID=0x50877ed6
    
    API_URL=https://staging-fast-active-bellatrix.explorer.staging-v3.skalenodes.com/api
    
    BLOCKEXPLORER_URL=https://staging-fast-active-bellatrix.explorer.staging-v3.skalenodes.com
    
    ETHERSCAN_API_KEY='abc123' /* <-- contents not important just needs populated string */
    1 Be sure to add your private key to your .env
    2
    🔭 Additional Chain info for the entire network is available here: Staging | Mainnet
    ❗️ Most chains are not open deployment and require whitelisting by the chain owner or operator

  3. Connect your .env with your hardhat.config

    hardhat.config

    require("@nomicfoundation/hardhat-toolbox");
    require("@nomiclabs/hardhat-etherscan");
    const dotenv = require("dotenv");
    
    
    dotenv.config();
    
    
    /** @type import('hardhat/config').HardhatUserConfig */
    module.exports = {
     solidity: "0.8.9",
    
     networks: {
    
     skale: { (1)
     url: process.env.SKALE_ENDPOINT,
    
     accounts: [process.env.PRIVATE_KEY]
     },
    
     },
     etherscan: { (2)
     apiKey: {
     skale: process.env.ETHERSCAN_API_KEY,
     },
     customChains: [ (3)
     {
     network: "skale",
     chainId: parseInt(process.env.CHAIN_ID),
     urls: {
     apiURL: process.env.API_URL,
     browserURL: process.env.BLOCKEXPLORER_URL,
     }
     }
     ]
     }
    };
    1 Update the networks block
    2 Add the etherscan block
    3 Within this etherscan block, add a customChains block

DEPLOYING

  1. To deploy your smart contracts from hardhat you will need to write or reuse a deployment script

    Certain plugins (e.g., hardhat-deploy ) can check previous transactions. If you are not connected to an Archive Node please use flags to disable the boolean for previous transactions check (for hardhat-deploy - skipIfAlreadyDeployed)

  2. You can now use the flag --network skale with your deployment scripts.

    Example deployment command:

    npx hardhat run ./scripts/<<your script>> --network skale
    After a successful deployment, the returned address will be used in the verification command. Save it before clearing your terminal!

VERIFYING

  1. Before verifying with hardhat CLI make sure you have installed the necessary dependencies:

    Dependencies:

    npm install --save-dev "@ethersproject/providers@^5.4.7" "@nomicfoundation/hardhat-network-helpers@^1.0.0" "@nomicfoundation/hardhat-chai-matchers@^1.0.0" "@nomiclabs/hardhat-ethers@^2.0.0" "@types/chai@^4.2.0" "@types/mocha@^9.1.0" "@typechain/ethers-v5@^10.1.0" "@typechain/hardhat@^6.1.2" "chai@^4.2.0" "ethers@^5.4.7" "hardhat-gas-reporter@^1.0.8" "solidity-coverage@^0.7.21" "ts-node@>=8.0.0" "typechain@^8.1.0" "typescript@>=4.5.0" "dotenv@^16.0.1" "@openzeppelin/contracts@^4.7.0" "@nomicfoundation/hardhat-toolbox@^1.0.2" "@nomiclabs/hardhat-etherscan@^3.1.5"
  2. Copy the address in the terminal returned from successfully deploying, and run the verification command

    Example deployment command:

    npx hardhat verify <<contract address>> --network skale "add any simple constructor"
    🛠️ If you have no constructors, the "add constructor" can be omitted
    🚧 See Hardhat Docs for handling complex constructors (multiple type constructors)
  3. After a few moments, hardhat will return a link to a verified contract if successful.

    ٭ Verification may take anywhere from a few seconds to a few minutes depending on contract size
    ٭ Upon successful verification, Hardhat will return Etherscan, but please use Blockscout. ( This is an artifact of the plugin )

Truffle is a popular way to deploy your smart contracts onto Ethereum, and can also be used to deploy your smart contracts onto SKALE. You can update your truffle configuration file (truffle-config.js) with a configuration to deploy your smart contracts onto SKALE.

For more information on truffle configuration files, please see (Truffle’s Configuration Documentation.

To deploy your smart contracts onto SKALE, the transaction needs to be signed. This code below shows how to use the @truffle/hdwallet-provider package to sign the transaction with the private key of your wallet.
/*
 * This truffle script will deploy your smart contracts to your SKALE Chain.
 *
 *  @param {String} privateKey - Provide your wallet private key.
 *  @param {String} provider - Provide your SKALE endpoint address.
 */

let HDWalletProvider = require("@truffle/hdwallet-provider");

//Provide your wallet private key
let privateKey = "[YOUR_PRIVATE_KEY]";

//Provide your SKALE endpoint address
let skale = "[YOUR_SKALE_CHAIN_ENDPOINT]";

module.exports = {
    networks: {
        ganache: {
            host: "127.0.0.1",
            port: 8545,
            network_id: "*"
        },
        skale: {
            provider: () => new HDWalletProvider(privateKey, skale),
            gasPrice: 0,
            network_id: "*"
        }
    }
}

You can point your deployment scripts for your existing smart contracts to your SKALE Chain’s address and deploy using existing tooling (e.g.: Truffle). An example truffle deployment command to deploy your smart contracts using the 'skale' network in the script above is:

truffle deploy --reset --network skale --compile-all

Node.jsSmart contracts can be deployed with just the use of web3.js as well. Below you will find a simple script for using NodeJS and web3.

Web3 and solc versions matter for compatibility. Web3 1.0.0-beta.35 and solc version 0.5.4 work well together, but other version combinations can cause unexpected errors.

For more information on using web3.js, please see Web3.js Ethereum JavaScript API.

/*
 * This nodeJS script will deploy your smart contracts to your new S-Chain.
 *
 *  @param {String} private key - Provide your private key.
 *  @param {String} account - Provide your account address.
 *  @param {String} SKALE Chain endpoint - provide your SKALE Chain endpoint
 *  @param {String} contractName - Name of your smart contract (i.e. MySmartContract)
 *  @param {String} contractFileName - Complete filename of contract (i.e. MySmartContract.sol)
 */

const Web3 = require('web3');
const solc = require('solc');
const path = require('path');
const fs = require('fs');

let privateKey = "[YOUR_PRIVATE_KEY]";
let account = "[YOUR_ACCOUNT_ADDRESS]";
let schainEndpoint = "[YOUR_SKALE_CHAIN_ENDPOINT]";

let contractName = "HelloSKALE"; //replace with your contract name
let contractFileName = "HelloSKALE.sol"; //replace with the filename of the contract

//Retrieve and compile contract source code
const contractPath = path.resolve(__dirname, 'contracts', contractFileName);
const contractContent = fs.readFileSync(contractPath, 'UTF-8');

//Format contract for solc reader
var contracts = {
  language: 'Solidity',
  sources: {},
  settings: {
    outputSelection: {
      '*': {
        '*': [ '*' ]
      }
    }
  }
}

//add HelloSKALE contract to contract sources
contracts.sources[contractFileName] = { content: contractContent };

//compile data via solc reader
let solcOutput = JSON.parse(solc.compile(JSON.stringify(contracts)));

//get compile HelloSKALE contract
let contractCompiled = solcOutput.contracts[contractFileName][contractName];

//Connect Web3 to your SKALE Chain
const web3 = new Web3(new Web3.providers.HttpProvider(schainEndpoint));


//create transaction
var tx = {
  data : '0x' + contractCompiled.evm.bytecode.object,
  from: account,
  gasPrice: 0,
  gas: 80000000
};

//sign transaction to deploy contract
web3.eth.accounts.signTransaction(tx, privateKey).then(signed => {
  web3.eth.sendSignedTransaction(signed.rawTransaction).
    on('receipt', receipt => {
     console.log(receipt)
   }).
    catch(console.error);
});

Smart contracts can be deployed using Remix and MetaMask. Follow the steps below to deploy your smart contracts.

For more information on using remix, please see Remix Documentation.

  1. In Remix’s Deploy & Run Transactions tab, select ENVIRONMENT  Injected Web3.

  2. With MetaMask, select Network  Custom RPC

  3. Enter your SKALE Chain endpoint

  4. Enter your ChainID.

5ce1657d7e30fb40711d2b31 rpc metamask

Deploy allows you to deploy a smart contract to any EVM compatible network without configuring RPC URLs, exposing your private keys, writing scripts, and other additional setup such as verifying your contract.

  1. To deploy your smart contract using deploy, navigate to the root directory of your project and execute the following command:

    npx thirdweb deploy

    Executing this command will trigger the following actions:

    • Compiling all the contracts in the current directory.

    • Providing the option to select which contract(s) you wish to deploy.

    • Uploading your contract source code (ABI) to IPFS.

  2. When it is completed, it will open a dashboard interface to finish filling out the parameters.

    • _name: contract name

    • _symbol: symbol or “ticker”

    • _royaltyRecipient: wallet address to receive royalties from secondary sales

    • _royaltyBps: basis points (bps) that will be given to the royalty recipient for each secondary sale, e.g. 500 = 5%

  3. Select Skale as the network

  4. Manage additional settings on your contract’s dashboard as needed such as uploading NFTs, configuring permissions, and more.

For additional information on Deploy, please reference thirdweb’s documentation.

If you have any further questions or encounter any issues during the process, please reach out to thirdweb support at support.thirdweb.com.