Skip to content

t3rn/hardhat-solang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hardhat-solang

npm version npm downloads

A hardhat plugin using solang instead of solc targeting solana and running tests against a solana-test-validator.

npm i t3rn/hardhat-solang @solana/web3.js @solana/solidity @solana/buffer-layout fast-glob

@solana/web3.js, @solana/solidity, @solana/buffer-layout, fast-glob, and hardhat are peer dependencies

Make sure to manually install llvm, solang, solana-test-validator and solana, and put them on your $PATH:

Usage

hardhat.config.js

require("hardhat-solang");

module.exports = {
  // don't pull solc
  solidity: undefined,
  // just use .defaultNetwork as .networks is absolutely ignored
  defaultNetwork: "localhost", // mainnet-beta, testnet, devnet
  paths: {
    sources: "./contracts",
    tests: "./contracts",
    artifacts: "./artifacts",
  },
  solang: { // depicted values are defaults
    target: "solana", // solana, substrate, ewasm
    optLevel: "default", // none, less, default, aggressive
    noConstantFolding: false,
    noStrengthReduce: false,
    noDeadStorage: false,
    noVectorToSlice: false,
    mathOverflow: false, // enable math overflow checks
    importMap: { /* openzeppelin: "./node_modules/@openzeppelin" */ }
  }
};

Tasks

hardhat compile

Compiles any .sol contracts with solang.

hardhat test

Runs tests against a solana-test-validator.

Hardhat Runtime Environment

Within your tests and scripts you can do sth like:

let { web3, solidity, bufferLayout, deploy } = require("hardhat");

web3: @solana/web3.js default export

solidity: @solana/solidity default export

bufferLayout: @solana/buffer-layout default export

let { contract, connection, payer, program, storage } = await localContract(
  name,
  abifile,
  args = [],
  space = 8192,
  url = "http://localhost:8899",
)

Deploys given contract locally returning a .contract object that is more familiar coming from ethereum land.

let programId = await deploy(
  filename, // "bundle.so"
  network, // "localhost"
  keypath, // ""
  signer, // ""
  airdrop // 419
)

Deploys a program off of the shared object filename from your artifacts. All params are optional, so that you can just do await deploy().

./test/plugin.test.js might serve as a little example

License

WTFPL

About

Plugin for using Hardhat with Solang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published