Hi,
So I’m writing this simple ERC1155. I’m also using Couters.sol
:
import "@openzeppelin/contracts/utils/Counters.sol";
My very basic ERC1155 looks like this:
contract Token is ERC1155 {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor(string memory uri_) ERC1155(uri_){}
function mintItem(uint256 amount_) public returns (uint256) {
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(msg.sender, newItemId, amount_, "");
return newItemId;
}
function currentId() public view returns (uint256) {
return _tokenIds.current();
}
}
Now when I’m minting using mintItem()
function I’m getting as a response a TX, which when finished mining looks like:
{
hash: '0xbb05d8640b16500eb280a7b1fba76c9d8773c22e9222626d66848b164ecf93e5',
type: 2,
accessList: [],
blockHash: '0x29192d29fc17612aa975574018d71f0894de91444a08348bb971aa849740ea58',
blockNumber: 7,
gasPrice: BigNumber { _hex: '0x5399d4a7', _isBigNumber: true },
maxPriorityFeePerGas: BigNumber { _hex: '0x3b9aca00', _isBigNumber: true },
maxFeePerGas: BigNumber { _hex: '0x6b98df4e', _isBigNumber: true },
gasLimit: BigNumber { _hex: '0x01bad518', _isBigNumber: true },
to: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
value: BigNumber { _hex: '0x00', _isBigNumber: true },
nonce: 6,
data: '0x17fb85940000000000000000000000000000000000000000000000000000000000000096',
r: '0x3eae88d7172f1e7adaa68dcc768c975ce91f95870cd4b08ded8377ecfbfd2fa3',
s: '0x68691235f8a355fe8e26fbbc307022a49378af399f614eb252f46d79618f56c1',
v: 0,
creates: null,
chainId: 31337,
wait: [Function (anonymous)]
}
Now here’s a problem, the mintItem()
function should return the Counters.Counter which is a struct with uint256. When I run the currentId()
I get the proper id. But how can I get the same thing from mintItem()
- to return the value of the id. Because that’s what it returns actually states in the contract, that it returns the _tokenIds
. But because it’s not pure/view it returns the TX.
At first I though it’s the data
string, but actually it’s not. The id number doesn’t match.
I’m using Hardhat and ethers.js