The plugin generates 0xWeb
classes for compiled solidity contracts, making the blockchain development transparent.
We use 📦 dequanto library for the classes
Install
Install automatically the dependencies and configurations
$ npm i 0xweb -g
$ 0xweb init --hardhat
Compile
any/directory/Foo.sol
pragma solidity ^0.8.2;
contract Foo {
string public name;
function setName(string memory _name) public {
name = _name;
}
}
Plugin adds also ability to specify the sources
folder. As per default this is /contracts/**.sol
$ npx hardhat compile --sources ./any/directory/
Use in local development
example.ts
import { Foo } from '@0xweb/hardhat/Foo/Foo.ts'
import { HardhatProvider } from '@dequanto/hardhat/HardhatProvider'
const deployer = new HardhatProvider();
const foo = await deployer.deployClass<Foo>(Foo, { arguments: [ 'Hello' ] });
const tx = await foo.setName('Hello world')
const receipt = await tx.wait();
const text = await foo.name();
Use already deployed contracts to any chain
If the contract is already deployed, initialize the contract with the Address as normal class. If the contract is deployed to any other chain - set also the client in constructor
example.ts
import { Foo } from '@0xweb/hardhat/Foo/Foo.ts'
import { EthWeb3Client } from '@dequanto/clients/EthWeb3Client'
const client = new EthWeb3Client();
const foo = new Foo('0x12345...', client);
const tx = await foo.setName('Hello world');
const receipt = tx.wait();
const text = await foo.name();
Additional parameters
npx hardhat compile --source /foo/bar/qux
- compiles solidity files which are located outside the /contracts
foldernpx hardhat compile --artifacts /dist
- set custom folder for artifacts (ABI JSONs and TS contracts)npx hardhat compile --watch
- Compile the sources and waits to recompile on changes