Package Exports
- @openzeppelin/contract-loader
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@openzeppelin/contract-loader) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
OpenZeppelin Contract Loader
Load contract objects from built artifacts or ABIs. Includes support for both web3-eth-contract and @truffle/contract objects.
Installation
npm install @openzeppelin/contract-loader
You will also need to install web3-eth-contract
and/or @truffle/contract
, depending on which abstractions you want to be able to load.
Usage
Basic setup
const { setupLoader } = require('@openzeppelin/contract-loader');
const loader = setupLoader({
provider,
defaultSender, // optional
defaultGas, // optional - defaults to 8 million
});
Loading web3 contracts
const web3Loader = loader.web3;
// Load from artifacts built by the compiler (stored in .json files)
const ERC20 = web3Loader.fromArtifacts('ERC20');
// Or load directly from an ABI
const abi = [ ... ];
const ERC20 = web3Loader.fromABI(abi);
// Deploy token
const token = await ERC20.deploy().send();
// Query blockchain state and send transactions
const balance = await token.methods.balanceOf(sender).call();
await token.methods.transfer(receiver, balance).send({ from: sender });
Loading truffle contracts
const truffleLoader = loader.truffle;
// Load from artifacts built by the compiler (stored in .json files)
const ERC20 = truffleLoader.fromArtifacts('ERC20');
// Or load directly from an ABI
const abi = [ ... ];
const ERC20 = truffleLoader.fromABI(abi);
// Deploy token
const token = await ERC20.new();
// Query blockchain state and send transactions
const balance = await token.balanceOf(sender);
await token.transfer(receiver, balance, { from: sender });