@webfans/supercell
v0.1.22
Published
# @webfans/supercell
Downloads
8
Readme
clientsdk
@webfans/supercell
安装与引入
npm install @nomiclabs/hardhat-ethers 或者yarn add @nomiclabs/hardhat-ethers
npm install @webfans/supercell 或者 yarn add @webfans/supercell
import SDK,{conNames,fromWei,toWei} from '@webfans/supercell'
import SDK,{conNames,fromWei,toWei} from 'SuperCell.es.js'
使用说明 1 初始化 Web3Provider
import { ethers,providers } from 'ethers'
let lib = new providers.Web3Provider(window.ethereum as any)
let chainID = 31337
1.1 非网页环境,但是有私钥
根据私钥生成钱包,然后用钱包创建sdk
let Wallet = new ethers.Wallet("38*****私钥"
,new ethers.providers.JsonRpcProvider("https://data-seed-prebsc-1-s3.binance.org:8545"))
let sdk = new SDK(Wallet,chainID)
2 初始化sdk 设置账户和合约地址
let accounts = await window.ethereum.enable();
console.log(accounts)
account=accounts[0]
let sdk = new SDK(lib,chainID)
sdk.setAccount(account)
//可选 用于合约地址更新
sdk.setAddressConfig({"Cell": "0x70e0bA845a1A0F2DA3359C97E0285013525FFC49",
"SCT": "0x4826533B4897376654Bb4d4AD88B7faFD0C98528",
"USDT": "0x99bbA657f2BbC93c02D617f8bA121cB8Fc104Acf",
"BUSD": "0x0E801D84Fa97b50751Dbf25036d067dCf18858bF",
"ETH": "0x8f86403A4DE0BB5791fa46B8e795C547942fE4Cf",
"Oracle": "0x9d4454B023096f34B160D6B654540c56A1F81688",
"Nucleus": "0x5eb3Bc0a489C5A8288765d2336659EbCA68FCd00"})
3 一些常用方法
//读区usdt 余额
let num = await sdk.getUSDTContract().getBalance()
console.log(num)
//检查usdt 是否给合约授权
let haveAllonce = await sdk.getUSDTContract().allowanceNucleus()
if(haveAllonce==false){
//使用usdt给合约授权
let tx = await sdk.getUSDTContract().approveNucleus()
}
//获取购买token 需要的usdt数量
let sctneedusdt = await sdk.getNucleusContract().getBuySctNeedUsdt(conNames.USDT,"100")
console.log('sctneedusdt',sctneedusdt.toString())
if(num.gte(sctneedusdt)){
}
//购买token
let data = await sdk.getNucleusContract().claim(conNames.USDT,"1")
4 数字转化常用的方法
console.log(fromWei('1'))
console.log(toWei('1'))
5 铸造nft 相关的
使用cst 铸造 nft 需要进行授权检测
let haveallowanceProxy = await sdk.getSCTContract().allowanceProxy()
if(haveallowanceProxy==false){
//使用CST token 对Proxy 进行授权
await sdk.getSCTContract().approveProxy()
}
//铸造的版本号
const STAGE1 = "1";
//铸造nft
let res = await sdk.getProxyContract().mint(STAGE1)
读区nft 相关
// 读区铸造nft 需要消耗的等价值的 cst 的usdt的数量
let needusdt = await sdk.getProxyContract().getStagePrices(STAGE1)
/////读区铸造nft 需要消耗的usdt的数量 将usdt数量转换为cst数量
let cstnum = await sdk.getMintUseCst(STAGE1)
console.log(' 换算后铸造需要消耗的cst',fromWei(cstnum.toString()))
// 读区账户上nft 的数量
let nftNum = await sdk.getCellContract().blanceOf()
// 获取账户 nft 的tokenid 的列表
let nftList = await sdk.getCellContract().listNft()
// 获取一个tokenid 的对应的token 的详细信息
let res2= await sdk.getCellContract().getTokenInfo(nftList[0].toString())
//读区账户 sct 的余额
let cst = await sdk.getSCTContract().getBlance()
//读区账户usdt 的余额
let myusdt = await sdk.getUSDTContract().getBlance()
只读模式
// 1创建 jsonrpc 接口
let readlib= new providers.JsonRpcProvider("https://data-seed-prebsc-1-s3.binance.org:8545")
//2 初始化sdk
let sdk = new SDK(readlib,chainID)
// 不要设置默认账户
// 生命力调用时候要传入的地址
let account="***"
const STAGE1 = "1";
//铸造1个nft 需要的usdt
let needUsdt = await sdk.getProxyContract().getStagePrices(STAGE1)
console.log('铸造1个nft 需要的usdt',fromWei(needUsdt.toString()))
let num = await sdk.getUSDTContract().getBalance(account)
console.log(num)
let native = await sdk.getNativeTokenBalance(account)
console.log('native',native)
let nftNum = await sdk.getCellContract().blanceOf(account)
console.log('nftNum',nftNum)
let nftList = await sdk.getCellContract().listNft(account)
console.log('nftList',nftList)
let res2= await sdk.getCellContract().getTokenInfo(nftList[0].toString())
console.log('token info',res2)
let pointRecords = await sdk.getCellContract().getpointRecords(account)
console.log('pointRecords',pointRecords)
let cstnum = await sdk.getSCTContract().getBalance(account)
console.log('cstnum',cstnum)
//预约
sdk.getCellContract().lock(tokenId,orderId)
//取消预约
sdk.getCellContract().unLock(tokenId)
//使用 一个nft
let ussnft = await sdk.getCellContract().use(tokenId)
Recommended IDE Setup
VSCode + Volar (and disable Vetur).
TypeScript
Customize configuration
See Vite Configuration Reference.
Project Setup
npm install
Compile and Hot-Reload for Development
npm run dev
Type-Check, Compile and Minify for Production
npm run build