cannot import ERC1155Burnable from openzeppelin library - solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "#openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
import "#openzeppelin/contracts/security/Pausable.sol";
import "#openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
import "./AdminContract.sol";
import "#openzeppelin/contracts/token/common/ERC2981.sol";
import "#openzeppelin-contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
import "#openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
/**
- Contract uses a single URI which is the monion IPFS URI for hosting metadata
- Contract relies on the metadata to store relevant info about the token such as name, description etc.
- Contract issues tokenId to each token minted
- Contract use is cheaper than if the user deployed a fresh instance of the ERC1155
*/
contract Monion1155 is ERC1155, Ownable, Pausable, ERC2981, ERC1155Supply, ERC1155Holder, ERC1155MintBurn, ERC1155Metadata {
event Minted (uint indexed tokenId,address indexed owner, uint quantity);
address operator;
AdminConsole admin;
while trying to import ERC1155
from openzeppelin library giving me the following error :
Error: not found #openzeppelin-contracts/token/ERC1155/extensions/ERC1155Burnable.sol
also someone suggested me to use ERC1155MintBurn but I dont think that library exist on openzep
ERC1155MintBurn
ERC1155MintBurn
ERC1155MintBurn
ERC1155MintBurn
ERC1155MintBurn
ERC1155MintBurn

import "#openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";

Related

'ERC20: insufficient allowance' when staking

Deployed an ERC20, that is set as an asset for separate staking contract (vault).
I was able to mint, transfer and increase allowance in the ERC20, but when trying to use the 'stake/deposit' function - this return:
Error: VM Exception while processing transaction: reverted with reason string 'ERC20: insufficient allowance'
The address is set as spender + owner, and on-chain calls verified the spender is aprroved under the ERC20.
Any ideas? I suspect it's related to proxy/contract routing.
Tried to stake ERC20 into a staking contract, received 'Allowance insufficient' error.
by any chance did you call the approve function on your ERC20 contract to approve the staking contract?
If you did, try to check your allowance again to the staking contract whether it is above the amount that you would like to stake. If the allowance to the staking contract is 0, then it will fail as you essentially have not give any permission from the staking contract to take your ERC20 token fro staking.
To check the token allowance to your staking contract, you can do so by using Moralis
import Moralis from 'moralis';
import { EvmChain } from '#moralisweb3/evm-utils';
try {
const chain = EvmChain.ETHEREUM;
const address = '';
const ownerAddress = '';
const spenderAddress = ''
await Moralis.start({
apiKey: 'YOUR_API_KEY',
// ...and any other configuration
});
const response = await Moralis.EvmApi.token.getTokenAllowance({
address,
chain,
});
console.log(response?.result);
} catch (e) {
console.error(e);
}
where the parameters are:
address is your ERC20 token address
chain is what chain your ERC20 token on
ownerAddress is the address that would like to stake the ERC20 token
spenderAddress is the staking contract
You can follow this tutorial further for more details https://docs.moralis.io/web3-data-api/evm/how-to-get-the-spender-allowance
Hope this helps!

deploy solidity smart contract

I am learning Solidity.
I wrote solidity code using openzeppelin and compile it using solcjs.
It returns multiple bytecode for main.sol and imported other sol file.
should I deploy only bytecode for main.sol?
(main.sol bytecode contains other sol files bytecode?)
I am not a native english speaker, so please forgive me my weird english.
pragma solidity ^0.8.0;
import "./contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "./contracts/utils/Counters.sol";
import "./contracts/access/Ownable.sol";
contract Name is ERC721URIStorage,Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721("Name", "name") {}
function mint(address nftowner)
public
onlyOwner
returns(uint256)
{
uint256 newItemId = _tokenIds.current();
_mint(nftowner, newItemId);
_setTokenURI(newItemId, "https://example.com");
_tokenIds.increment();
return newItemId;
}
}
On remix select the main contract with your logic to deploy. It will deploy all the dependencies as well.
Id suggest installing the etherscan plugin and making an account on their website to get an etherscan API_KEY to verify your contracts easily.
If you're not using framework like Hardhat or truffle then use remix injected web3 it's the easiest way to deploy
To deploy a smart contract, I recommend you use either Hardhat (if your familiar with JavaScript) or Foundry/Forge (which is in Solidity)
If you want to use Hardhat, you can create a deploy script like explained here in a JS file inside the scripts folder of your project:
const hardhat = require("hardhat");
async function main() {
const Contract = await hardhat.ethers.getContractFactory("YourContract");
const contract = await Contract.deploy();
await contract.deployed();
console.log(`Contract address: ${contract.address}`);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Then, you can run the script with this command:
npx hardhat run --network <your-network> scripts/deploy.js
And you can verify your contract on Etherscan with this command
npx hardhat verify --network <your-network> <contract-address>
Both commands require some configuration in the Hardhat config file. Check the article above or the documentation for more info!
Or check out this article if you prefer to use Foundry

How to deploy a pre-compiled contract to hardhat node

I have a proxy contract and would like to replace the underlying implementation contract.
I already have the abi & bytecode of a smart contract(retrieved from artifacts folder), so here is what I did:
const NFTv2 = await ethers.getContractFactory(upgradedContract.abi, upgradedContract.bytecode);
contract = await upgrades.upgradeProxy(proxyContract.address, NFTv2);
It works fine, but I don't want the contract to exist in my contracts folder, so I've deleted it and run npx hardhat compile again.
Now when I try to run this deploy script again, hardhat keep throwing this error:
Error: The requested contract was not found. Make sure the source code is available for compilation
at getContractNameAndRunValidation (node_modules/#openzeppelin/upgrades-core/src/validate/query.ts:46:11)
at Object.getStorageLayout (node_modules/#openzeppelin/upgrades-core/src/validate/query.ts:54:41)
at Object.deployImpl (node_modules/#openzeppelin/hardhat-upgrades/src/utils/deploy-impl.ts:30:18)
at Proxy.upgradeProxy (node_modules/#openzeppelin/hardhat-upgrades/src/upgrade-proxy.ts:36:22)
After some try & error, it seems to be related to the cache folder, once the related metadata inside the cache folder disappeared, then this error will pop out, otherwise no.
Can someone guide me on this problem and how can I deploy contract with only abi & bytecode without leaving the contract inside the contracts folder?
Thank you! :)
Here's the code of my upgraded contract:
// SPDX-License-Identifier: Apache2.0
pragma solidity ^0.8.4;
import "#openzeppelin/contracts-upgradeable/token/ERC1155/presets/ERC1155PresetMinterPauserUpgradeable.sol";
contract Test is ERC1155PresetMinterPauserUpgradeable {
string private _uri;
event upgradeEvent(string);
function uri(uint256) public view virtual override returns (string memory) {
return string(abi.encodePacked(_uri, "/new"));
}
function seturi(string memory uri) public {
emit upgradeEvent("this is an upgraded contract");
_uri = uri;
}
}
I stumbled upon this question because I struggled with the same issue, but here is what I did in the end. Basic idea is to ignore the API extensions provided by Hardhat and use Ethers.js directly.
const allSigners = await hre.ethers.getSigners();
const deployingSigner = allSigners[0];
const factory = new ContractFactory(artifact.abi, artifact.bytecode, deployingSigner);
const contract = await factory.deploy(); // no args
await contract.deployed();
console.log("Contract deployed to: ", contract.address);

Why in multiple connections to PricesResource Publisher, only one gets the stream?

It seems that only one http client gets the stream of data, while the others do not.
Is it true that the Publisher is hot data, and that it should broadcast to all subscribers?
Please find more in Can I allow multiple http clients to consume a Flowable stream of data with resteasy-rxjava2 / quarkus?
package org.acme.kafka;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import io.reactivex.Flowable;
import io.reactivex.Observable;
import org.jboss.resteasy.annotations.SseElementType;
import org.reactivestreams.Publisher;
import io.smallrye.reactive.messaging.annotations.Channel;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static io.reactivex.Flowable.fromIterable;
/**
* A simple resource retrieving the "in-memory" "my-data-stream" and sending the items to a server sent event.
*/
#Path("/migrations")
public class StreamingResource {
private volatile Map<String, String> counterBySystemDate = new ConcurrentHashMap<>();
#Inject
#Channel("migrations")
Flowable<String> counters;
#GET
#Path("/stream")
#Produces(MediaType.SERVER_SENT_EVENTS) // denotes that server side events (SSE) will be produced
#SseElementType("text/plain") // denotes that the contained data, within this SSE, is just regular text/plain data
public Publisher<String> stream() {
Flowable<String> mainStream = counters.doOnNext(dateSystemToCount -> {
String key = dateSystemToCount.substring(0, dateSystemToCount.lastIndexOf("_"));
counterBySystemDate.put(key, dateSystemToCount);
});
return fromIterable(counterBySystemDate.values().stream().sorted().collect(Collectors.toList()))
.concatWith(mainStream)
.onBackpressureLatest();
}
}
You may use Replay operator or ConnectableObservable
What I did then was to inject the messages coming on the Flowable into a PublishSubject pipe and apply a backpressure strategy, thus offering a broadcast downstream.

Cannot able to call the contract inside the truffle console

I am new to the truffle framework. I have initialised my contract Dapp with the constructor function as given below
pragma solidity ^0.5.0;
contract Dapp {
uint public totalSupply;
constructor() public {
totalSupply = 1000000;
}
}
and my migrations file in regards with the contract is
const Dapp = artifacts.require("Dapp");
module.exports = function(deployer) {
deployer.deploy(Dapp);
};
I have compiled and migrated using the command truffle compile and truffle migrate, which results in successful compilation.
But when accessing the contract in truffle console like
let instance = await Dapp.deployed()
It results in ReferenceError: Dapp is not defined, I cannot able to figure out what went wrong. Is there any possible solution to this. And yeah I have followed the latest Truffle documentation. And also, I have followed the solution been presented in this platform.
Documentation link for migration and interacting with truffle console.