@white-matrix/nft-vspark-sdk
v1.1.0
Published
## how to use
Downloads
4
Keywords
Readme
Solidity SDK Seed
how to use
sample example
const provider = new ethers.providers.Web3Provider(window.ethereum);
const singer = provider.getSigner();
const network = '';
const vspark = new EtherVSParkClient();
vspark.connectProvider(DeploymentInfo[network].vspark.proxyAddress, provider);
vspark.connectSigner(singer);
vspark.setWaitConfirmations(1);
const BUSDAddress = await vspark.BUSD();
const BUSD = new EtherERC20Client();
BUSD.connectProvider(BUSDAddress, provider);
BUSD.connectSigner(singer);
BUSD.setWaitConfirmations(1);
remind
approve BUSD before buy vspark
if(BUSD.allowance(user.address,vspark.address)<balance){
await BUSD.approve(vspark.address,balance)
}
interface
export interface VSParkClient extends ERC721Client {
connectProvider(address: string, provider: Provider): VSParkClient;
connectSigner(signer: Signer): VSParkClient;
/*======== VSParkClient specific ======*/
BUSD(): Promise<string>;
/* view */
/**
* Check current stock
*/
stock(): Promise<BigNumber>;
/**
* Get tokenCount
*/
tokenCount(): Promise<BigNumber>;
/**
* Return on current box price
*/
boxPrice(): Promise<BigNumber>;
/**
* Return the series
* @param seriesId
* @param config ethers PayableOverrides
*/
series(seriesId: BigNumber): Promise<VSParkSeries>;
/**
* Return on chain item detail information
* @param tokenId
* @param config ethers PayableOverrides
* @returns produceDetail on chain item detail data structure
*/
tokenDetail(tokenId: BigNumber): Promise<[BigNumber, BigNumber]>;
/**
* Verify the recycle transaction
* @param tokenIds the tokens needs to be recycled
* @param seriesId used to verify the recycle
* @return true if the recycle will success and the recycle price; or false if recycle will fail
*/
verifyRecycle(tokenIds: BigNumber[], seriesId: BigNumber): Promise<[boolean, BigNumber]>;
/* transactions */
/**
* Buy N boxes (N <= 10 for current setup)
* @param quantity number of boxes, will trigger Web3Provider to send transaction in browser
* @param config ethers PayableOverrides
* @return BuyResult including transactionHash and a list of awarded tokenIds
*/
buy(quantity: BigNumber, config?: PayableOverrides): Promise<ContractBuyResult>;
/**
* Recycle the attached tokens
* @param tokenIds the tokens needs to be recycled
* @param seriesId
* @return ContractRecycleResult indicates the success or failure of this recycle transaction
*/
recycle(tokenIds: BigNumber[], seriesId: BigNumber, config?: PayableOverrides): Promise<ContractRecycleResult>;
tokenOfOwnerByIndex(owner: string, index: BigNumber): Promise<BigNumber>;
totalSupply(): Promise<BigNumber>;
tokenByIndex(index: BigNumber): Promise<BigNumber>;
/* test function */
mint(categoryIds: BigNumber[], config?: PayableOverrides): Promise<ContractBuyResult>;
}
export interface ERC20Client {
connectProvider(address: string, provider: Provider): ERC20Client;
connectSigner(signer: Signer): ERC20Client;
setWaitConfirmations(num: number): void;
/*======== ERC20 standard API ======*/
/* view function */
balanceOf(owner: string): Promise<BigNumber>;
name(): Promise<string>;
symbol(): Promise<string>;
decimals(): Promise<number>;
allowance(owner: string, spender: string): Promise<BigNumber>;
transfer(recipient: string, tokenId: BigNumber, config?: PayableOverrides): Promise<string>;
transferFrom(from: string, to: string, tokenId: BigNumber, config?: PayableOverrides): Promise<string>;
approve(spender:string, amount: BigNumber, config?: PayableOverrides): Promise<string>;
}