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
, andhardhat
are peer dependencies
Make sure to manually install llvm
, solang
, solana-test-validator
and solana
, and put them on your $PATH
:
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" */ }
}
};
Compiles any .sol
contracts with solang
.
Runs tests against a solana-test-validator
.
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