Update docs
This commit is contained in:
@ -136,7 +136,7 @@ In order for our contract to receive ERC1155 tokens we can inherit from the conv
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC1155/ERC1155Holder.sol";
|
||||
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
|
||||
|
||||
contract MyContract is ERC1155Holder {
|
||||
}
|
||||
|
||||
@ -58,9 +58,9 @@ To work around this, xref:api:token/ERC20.adoc#ERC20[`ERC20`] provides a xref:ap
|
||||
|
||||
How can this be achieved? It's actually very simple: a token contract can use larger integer values, so that a balance of `50` will represent `5 GLD`, a transfer of `15` will correspond to `1.5 GLD` being sent, and so on.
|
||||
|
||||
It is important to understand that `decimals` is _only used for display purposes_. All arithmetic inside the contract is still performed on integers, and it is the different user interfaces (wallets, exchanges, etc.) that must adjust the displayed values according to `decimals`. The total token supply and balance of each account are not specified in `GLD`: you need to divide by `10^decimals` to get the actual `GLD` amount.
|
||||
It is important to understand that `decimals` is _only used for display purposes_. All arithmetic inside the contract is still performed on integers, and it is the different user interfaces (wallets, exchanges, etc.) that must adjust the displayed values according to `decimals`. The total token supply and balance of each account are not specified in `GLD`: you need to divide by `10 ** decimals` to get the actual `GLD` amount.
|
||||
|
||||
You'll probably want to use a `decimals` value of `18`, just like Ether and most ERC20 token contracts in use, unless you have a very special reason not to. When minting tokens or transferring them around, you will be actually sending the number `num GLD * 10^decimals`.
|
||||
You'll probably want to use a `decimals` value of `18`, just like Ether and most ERC20 token contracts in use, unless you have a very special reason not to. When minting tokens or transferring them around, you will be actually sending the number `num GLD * (10 ** decimals)`.
|
||||
|
||||
NOTE: By default, `ERC20` uses a value of `18` for `decimals`. To use a different value, you will need to override the `decimals()` function in your contract.
|
||||
|
||||
@ -73,7 +73,7 @@ function decimals() public view virtual override returns (uint8) {
|
||||
So if you want to send `5` tokens using a token contract with 18 decimals, the method to call will actually be:
|
||||
|
||||
```solidity
|
||||
transfer(recipient, 5 * 10^18);
|
||||
transfer(recipient, 5 * (10 ** 18));
|
||||
```
|
||||
|
||||
[[Presets]]
|
||||
|
||||
@ -16,7 +16,6 @@ Here's what a contract for tokenized items might look like:
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
|
||||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
|
||||
import "@openzeppelin/contracts/utils/Counters.sol";
|
||||
|
||||
@ -30,12 +29,11 @@ contract GameItem is ERC721URIStorage {
|
||||
public
|
||||
returns (uint256)
|
||||
{
|
||||
_tokenIds.increment();
|
||||
|
||||
uint256 newItemId = _tokenIds.current();
|
||||
_mint(player, newItemId);
|
||||
_setTokenURI(newItemId, tokenURI);
|
||||
|
||||
_tokenIds.increment();
|
||||
return newItemId;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user