This is a Node JS application that connects to the ethereum blockchain via Web3 and Bitski and interacts with a smart contract as a data source.
We built this example to show what is possible using Bitski's app wallet, and to experiment with patterns for interacting with ethereum server-side.
Our smart contract is a simple non-fungible token that can be minted for free, with a limit of 5 tokens per address. We allow our users to request a token by POST-ing to /tokens/new, and host the metadata of the token by reading from the smart contract.
Bitski's Node SDK allows you to easily read from Ethereum in Node, and with App Wallet you can also create server-side transactions.
The entry point is index.js, which simply creates an instance of App. The source code for that class is under /app/. App is responsible for creating the Express http server and handling the requests.
App creates an instance of Contract, which is just a wrapper around Web3's contract module, and truffle artifacts. It pulls in the compiled contract ABI (generated by Truffle), extracts the deployed address, and creates an instance of that contract with web3.
Check out app.js to see the various routes that are exposed.
Powering all the data for this app is an Ethereum smart contract. It's written in Solidity, and based off of OpenZeppelin's NFT templates. You can view the source code for the main contract under contracts/LimitedMintableNonFungibleToken.sol.
First, install the dependencies via NPM:
npm install
Next, create an app on Bitski's Developer Portal, create an App Wallet for your app, and enter your details into a .env file like so:
BITSKI_APP_WALLET_ID=YOUR-CREDENTIAL-ID-HERE
BITSKI_APP_WALLET_SECRET=YOUR-CREDENTIAL-SECRET-HERE
Finally, you can run the app with:
npm run start
You can create a bitski.config.js and use Truffle to deploy your own version of this contract with your App Wallet.