How to Create Your Own Store on HashUp?
HashUp's mission is to power thousands of stores at once!
Last updated
import { useHashup } from "@hashup-it/hashup-react-sdk" function App() {
const { buyGame } = useHashup()
return ( <div className="App"> /*Your app code*/ </div> )} ...
const { buyGame } = useHashup()
function handleBuy() {
const license = "0x6cbf4648d1f326585f7aa768913991efc0f2b952" // Specify address of license you want to buy
const amount = "200" // Specify amount of license you want to buy
buyGame(license, amount)
}
......
const { setMarketplace } = useHashup()
function handleSetMarketplace() {
const marketplace = "0x714EF5c429ce9bDD0cAC3631D30474bd04e954Dc"; // Overwrite the default HashUp marketplace with yours
setMarketplace(marketplace)
}
......
const { approve } = useHashup()
function handleApprove() {
approve()
}
...interface UseHashupOutput {
/**
* Allows for ahead-of-time payment approval. Called automatically by `buyGame()`.
*/
approve: () => Promise<void>
/**
* Purchases a license. Defaults to one token bought, i.e. 100 units.
* @param address address of ERC20 licence about to be bought
* @param amount amount of token units bought (unit is 0.01 of a token)
*/
buyGame: (address: string, amount?: string) => Promise<string | void>
/**
* HashUp-protocol lifecycle state. Affected by `buyGame()` method call.
* @default BuyStage.NOT_STARTED
*/
buyingStage: BuyStage
/**
* HashUp-protocol wallet connection init status
*/
isEthereumLoading: boolean
/**
* HashUp-protocol network compatibility status
*/
isNetworkValid: boolean
/**
* Sets a custom marketplace. Defaults to HashUp.
* @param marketplace blockchain address
*/
setMarketplace: React.Dispatch<React.SetStateAction<string>>
/**
* Sets a reflink variable. Affects `buyGame()` method call.
* @param referrer purchase referrer's blockchain address
*/
setReferrer: React.Dispatch<React.SetStateAction<string>>
} <div className="App">
//Your app code
</div>
);
}function App() {
const { buyGame } = useHashup()
//API Integration
//This data you can get by integrating with HashUp Open API
const licenseAddress = "0x123 ... abc" // Specify address of license you want to buy
const licenseAmount = 2 // Specify amount of licenses you want to buy
function handleLicenseBuy() {
buyGame(licenseAddress, licenseAmount)
}
return (
<div className="App">
<button onClick={handleLicenseBuy}>Buy 2 copies of game</button>
</div>
);
}//Sample request in axios
const axios = require('axios')
const getAllHashUpLicenses = async () => {
const { data } = await axios.get('http://open-api.hashup.it/v1/tokens')
console.log(data)
return data;
}
getAllHashUpLicenses()
//Returns an array of The HashUp Licenses