Reputation: 1787
I'm working to deploy an ERC777 token using hardhat, ethers in typescript. My deployment script is as follows
import { MarketSvc, ProductSvc } from '../libs/deployment-service/src';
import hre from 'hardhat';
async function main() {
const marketAddress = await MarketSvc.deployContract(contractType);
const productAddress = await ProductSvc.deployContract(contractType, marketAddress);
}
my execution function looks like this
async deployContract(
contractType: ContractType,
...args: any[]
): Promise<string> {
const contractFactory = await hre.ethers.getContractFactory(contractType);
const contract =
args === undefined
? await contractFactory.deploy()
: await contractFactory.deploy(...args);
await contract.deployed();
console.log(contractType + ' Contract deployed to:', contract.address);
return contract.address;
}
The first deployment succeeds. The second deployment fails with and error of
MarketContract Contract deployed to: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
ProviderError: Error: Transaction reverted: function call to a non-contract account
at HttpProvider.request (C:\src\trae\gbc\exchange\exchange_ui\node_modules\hardhat\src\internal\core\providers\http.ts:49:19)
at GanacheGasMultiplierProvider.request (C:\src\trae\gbc\exchange\exchange_ui\node_modules\hardhat\src\internal\core\providers\gas-providers.ts:312:34)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
In the ERC777 contract it is failing in the method below (@openzeppelin\contracts\token\ERC777\ERC777.sol:75)
/**
* @dev `defaultOperators` may be an empty array.
*/
constructor(
string memory name_,
string memory symbol_,
address[] memory defaultOperators_
) {
_name = name_;
_symbol = symbol_;
_defaultOperatorsArray = defaultOperators_;
for (uint256 i = 0; i < defaultOperators_.length; i++) {
_defaultOperators[defaultOperators_[i]] = true;
}
console.log("added operators");
// register interfaces - It is failing here
_ERC1820_REGISTRY.setInterfaceImplementer(address(this), keccak256("ERC777Token"), address(this));
console.log("registered ERC777");
_ERC1820_REGISTRY.setInterfaceImplementer(address(this), keccak256("ERC20Token"), address(this));
}
the constructor to my contract is this
constructor(address defaultOperator)
ERC777("SOMEtoken", "TKN", _defaultOps(defaultOperator)) {
console.log(defaultOperator);
_mint(_msgSender(), 1000000, "Initial Mint", "defaultOps");
}
my solidity log is
Error: Transaction reverted: function call to a non-contract account
at GParticle.constructor (@openzeppelin/contracts/token/ERC777/ERC777.sol:75)
at EthModule._estimateGasAction (C:\src\trae\gbc\exchange\exchange_ui\node_modules\hardhat\src\internal\hardhat-network\provider\modules\eth.ts:425:7)
at HardhatNetworkProvider._sendWithLogging (C:\src\trae\gbc\exchange\exchange_ui\node_modules\hardhat\src\internal\hardhat-network\provider\provider.ts:138:22)
at HardhatNetworkProvider.request (C:\src\trae\gbc\exchange\exchange_ui\node_modules\hardhat\src\internal\hardhat-network\provider\provider.ts:115:18)
at JsonRpcHandler._handleRequest (C:\src\trae\gbc\exchange\exchange_ui\node_modules\hardhat\src\internal\hardhat-network\jsonrpc\handler.ts:188:20)
at JsonRpcHandler._handleSingleRequest (C:\src\trae\gbc\exchange\exchange_ui\node_modules\hardhat\src\internal\hardhat-network\jsonrpc\handler.ts:167:17)
at Server.JsonRpcHandler.handleHttp (C:\src\trae\gbc\exchange\exchange_ui\node_modules\hardhat\src\internal\hardhat-network\jsonrpc\handler.ts:52:21)
the operator address I'm giving it, is defiantly deployed and is a contract. but so I'm a bit baffled about what could possibly be happening in the 777 contract specifically. I have a ERC20 and 1155 that deploy perfectly...
If anyone has any insight, all information is appreciated.
Upvotes: 1
Views: 497
Reputation: 92
I implemented a full deployment of ERC1820 & ERC777, my code checks if it's not deployed, deploys it, and then deploys the ERC777 and registers the recipient, It's implemented with hardhat and I put the guide in the readme.md
This is my repo :
https://github.com/EhsanParsania/ERC777
Upvotes: 1
Reputation: 1787
The root of the issue is that if you're working on a localnet, like hardhat... you will have to deploy your own ERC1820_REGISTRY, because it does not exist.
openzepplin has some utilites you can use to enable this pretty simply..
const { singletons } = require('@openzeppelin/test-helpers');
require('@openzeppelin/test-helpers/configure')
async function main() {
const signers = await hre.ethers.getSigners();
const address = signers[0].address;
const erc1820 = await singletons.ERC1820Registry(address);
... deploy your ERC777
}
Upvotes: 1