This project is not being actively supported, the code is not expected to work nor reflects the latests improvements in our tooling stack
This project is based on Truffle's Pet Shop Tutorial but uses NEAR's custom provider called near-web3-provider and deploys the Solidity contracts to the NEAR EVM.
You may read more about the NEAR EVM in the link above. In brief, it's an implementation of the Ethereum Virtual Machine (EVM) incorporated into NEAR. This means developers may preserve existing investment by compiling existing Ethereum contracts and deploying them to the NEAR blockchain as well.
This is made possible by two NEAR libraries:
- near-api-js: the JavaScript library used to abstract JSON RPC calls.
- near-web3-provider: the web3 provider for NEAR containing utilities and Ethereum routes (ex.
eth_call
,eth_getBlockByHash
, etc.)
This project uses Truffle for testing and migrating. Migrating, in this sense, also means deploying to an environment. Please see truffle-config.js
for network connection details.
mkdir near-pet-shop
cd near-pet-shop
npx truffle unbox near-examples/near-pet-shop
If you don't have a NEAR Betanet account, please create one using the Wallet interface at: https://wallet.betanet.near.org
Note: for instructions on migrating to a local NEAR environment, please read these instructions.
Replace YOUR_NAME
in the command below and run it:
env NEAR_MASTER_ACCOUNT=YOUR_NAME.betanet npx truffle migrate --network near_betanet
npm run betanet
On this site you'll see a grid of pets to adopt with corresponding Adopt buttons.
The first time you run this app, the Adopt buttons will be disabled until you've logged in. Click on the Login button in the upper-right corner of the screen. You will be redirected to the NEAR Betanet Wallet and asked to confirm creating a function-call access key, which you'll want to allow. After allowing, you're redirected back to Pet Shop, and a special key exists in your browser's local storage.
Now you can adopt a pet! Once you've clicked the Adopt button pay attention to the top of the page, as a link to NEAR Explorer will appear. (This is similar to etherscan for Ethereum.)
Run a local nearcore
node following these instructions. Then run:
npm run test
During development while changing the Solidity code, if unexpected behavior continues, consider removing the build
folder and migrating again.