创建智能合约 fuji网络
参考:
https://docs.avax.network/build/tutorials/platform/fuji-workflow/
1. 浏览器(firefox, chrome)安装metamask 扩展
2. 增加网络入口:
Avalanche Mainnet Settings:
Network Name: Avalanche Mainnet C-Chain
New RPC URL: https://api.avax.network/ext/bc/C/rpc
ChainID: 43114
Symbol: AVAX
Explorer: https://snowtrace.io/
FUJI Testnet Settings:
Network Name: Avalanche FUJI C-Chain
New RPC URL: https://api.avax-test.network/ext/bc/C/rpc
ChainID: 43113
Symbol: AVAX
Explorer: https://testnet.snowtrace.io/
3. 在metamask上增加好之后,切换到该网络
4. metamask 测试address
5. 打开 这个地址: https://faucet.avax-test.network/ , 做一下人机校验,就可以填写收款地址了:

7. 打开: https://testnet.snowtrace.io/ 输入对应的tx id ,
https://testnet.snowtrace.io/tx/0x5c5546ca305f5030d66f6a1655277d301faf9ce12672b11dd6179eb6c2690df8
可以看到对应的内容:
(注意,不要来这里 : https://explorer.avax-test.network/ 查不到的)
8创建智能合约
https://remix.ethereum.org/#optimize=false&runs=200&evmVersion=null&version=soljson-v0.8.15+commit.e14f2714.js&language=Solidity
编译,创建新文件hi.sol
内容如下
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
contract CompleteNftExample is ERC721URIStorage {
/**
* contract creator 就是root 用户
*/
constructor() ERC721("CompleteNftExample", "SSS") {
rootAddress = msg.sender;
}
// 已经发放的最新的NFT ID
uint256 private _currentId = 0;
// root用户的address
address public rootAddress = address(0);
// NFT的最大供应量
uint256 public _maxSupply = 100;
// 可以领取nft的地址白名单
mapping(address => uint) private whiteList;
event MintedEventLog(address to, uint256 nftId, address minter);
event AddToWhiteListEventLog(address the_address);
event RemoveFromWhiteListEventLog(address the_address);
// 必须是root 用户
modifier shouldBeRoot(){
string memory message = string.concat("The caller address(", toAsciiString(msg.sender), ") is not the contract root.");
require( rootAddress == msg.sender, message);
_;
}
// 必须在地址白名单中
modifier shouldInWhiteList(address to){
string memory message = string.concat("This address( ", toAsciiString(to), " ) is not in white list");
require( whiteList[to] > 0, message);
_;
}
// 该NFT必须是可以领取的状态
modifier shouldLessThanMaxSupply(){
string memory message = string.concat("Reached max supply:(_maxSupply: ", Strings.toString(_maxSupply), ", _currentId: ", Strings.toString(_currentId), "), no available nft left");
require( _currentId < _maxSupply, message);
_;
}
/**
* 挖nft, 参数:to 获得nft的地址
*/
function mint(address to) external shouldLessThanMaxSupply shouldInWhiteList(to) {
uint256 nftId = _currentId + 1;
_mint(to, nftId);
removeFromWhiteList(to);
_currentId = nftId;
address from = msg.sender;
emit MintedEventLog(to, nftId, from);
}
/**
* 确定一个地址是否在whiteList中。
* 0 :不存在
* 3 : 可以领取3次
*/
function isInWhiteList(address theAddress) public view returns(uint){
return whiteList[theAddress];
}
/**
* 把多个地址放到whiteList 中
*/
function addToWhiteList(address[] calldata addresses) external shouldBeRoot {
for(uint i = 0; i < addresses.length; i++ ) {
whiteList[addresses[i]] = whiteList[addresses[i]] + 1;
emit AddToWhiteListEventLog(addresses[i]);
}
}
/**
* 把1个address 的“对应记录”从 whitelist中删掉
*/
function removeFromWhiteList(address tempAddress) public {
if(whiteList[tempAddress] > 0 ){
whiteList[tempAddress] = whiteList[tempAddress] - 1;
emit RemoveFromWhiteListEventLog(tempAddress);
}
}
/**
* 转换address -> string
*/
function toAsciiString(address x) internal pure returns (string memory) {
bytes memory s = new bytes(40);
for (uint i = 0; i < 20; i++) {
bytes1 b = bytes1(uint8(uint(uint160(x)) / (2**(8*(19 - i)))));
bytes1 hi = bytes1(uint8(b) / 16);
bytes1 lo = bytes1(uint8(b) - 16 * uint8(hi));
s[2*i] = char(hi);
s[2*i+1] = char(lo);
}
return string(s);
}
function char(bytes1 b) internal pure returns (bytes1 c) {
if (uint8(b) < 10) return bytes1(uint8(b) + 0x30);
else return bytes1(uint8(b) + 0x57);
}
}
这里是添加合约的名称和代币的名称,最多100个

点击进行编译

进行deploy

添加白名单

例如这样:["0x960781B058da688735c98D5165aF8FF4e1B400E0", "0x0f8DA5C0b8ecdA1df8048f7B56aB94Efe1A5Dfa2", "0x960781B058da688735c98D5165aF8FF4e1B400E0","0x960781B058da688735c98D5165aF8FF4e1B400E0","0x653799445f963236D70387A439d4739aeFFcAc88","0x6De3fB47EDd3b692024dbEDEB705A07C5DC351d1",
"0x6De3fB47EDd3b692024dbEDEB705A07C5DC351d1"]
查看abi

查看contract address 0xbc61652e3Ec01e883c8AbF8b36E18576aB01A3a1

查看log

查看hash