This app was initialized with create-near-app
If you haven't installed dependencies during setup:
yarn
Build and deploy your contract to Mainnet:
NEAR_ENV=mainnet near login
yarn build
NEAR_ENV=mainnet deploy --accountId YOUR_ACCOUNT_ID_ON_MAINNET --wasmFile contract/build/events.wasm
- The smart-contract code lives in the
/contract
folder. See the README there for more info. In blockchain apps, the smart contract is the "backend" of your app. - The near.social code lives in the
/near.social
folder. - Test your contract:
yarn test
, this will run the tests in theintegration-tests
directory.
-
Adjust Environment Variables in
near.social/.env
file -
Run the local development environment:
NEAR_ENV=mainnet yarn start
This will start the local near.social dev-server which will automatically redeploy your widgets on near.social mainnet when you change the code in the widgets
folder.
- Automatic redeployment:
Widgets will automatically be redeployed on near.social when you change the code in the
widgets
folder. - Automatic widget registration:
Widgets will be named after the folder they are in, so if you want to deploy a widget called
my-widget
, you should create a file calledcomponent.jsx
in thewidgets
folder. Nested folders will be flattened, so if you you create a file calledmy-widget/component.jsx
, the widget will be namedmy-widget__component
on near.social. - env var substitution:
You can use environment variables in your widget code. For example, any occurence of
{{ env.MY_VAR }}
will be replaced with the value of theMY_VAR
environment variable from an .env file. .env files are loaded from thewidgets
folder and from the widget file's context. For example, if you have a file calledwidgets/my-widget/.env
and a file calledwidgets/my-widget/component.jsx
, the .env file will be loaded for thecomponent.jsx
file. This works recursively, so if you have a file calledwidgets/.env
and a file calledwidgets/my-widget/nested/component.jsx
, the .env file will also be loaded for thecomponent.jsx
file. Only the topmost .env file will be loaded for each widget file. If you want a widget to have its own .env file, you can create a folder for it and put the .env file in that folder. For example, if you have a file calledwidgets/my-widget/component.jsx
and a file calledwidgets/my-widget/component/.env
, the .env file will be loaded for thecomponent.jsx
file, but not for any other widget files except for child widget files in thecomponent
folder. - Speed
Widgets will be deployed on near.social as soon as you change the code in the
widgets
folder. This means that you can develop your widgets locally and deploy them on near.social as soon as you're ready. - App-like structure
Widgets following this structure will have access to common components and utilities:
- Widgets can render child widgets by referencing their names (e.g.
renderComponent('some_widget.child.another', {})
). - Widgets can within layouts (e.g.
renderComponent('some_widget.child.another', {}, 'container')
). - Router with methods for navigating between pages (e.g.
push('some_widget')
andpop()
). - Shared Components (e.g.
props.__engine.Components.Button
). - Overlays/Modals via layouts (e.g.
renderComponent('some_widget.child.another', {}, 'modal')
). This is useful for widgets that need to render a modal on top of the current page.
- Widgets can render child widgets by referencing their names (e.g.
widgets
folder: This folder contains all the widgets that will be deployed on near.social. Each widget should be in its own folder. The folder name will be used as the widget name. For example, if you have a file calledwidgets/my-widget/component.jsx
, the widget will be namedmy-widget__component
on near.social. Nested folders will be flattened, so if you you create a file calledmy-widget/parent/component.jsx
, the widget will be namedmy-widget__parent__component
on near.social.widgets/.env
file: This file contains environment variables that will be used for all widgets. You can override these variables in the widget's .env file.- TODO: automatic upload of widget metadata
-
- read metadata file from disc
-
- check if image files from metadata file exist on ipfs
-
- upload images from metadata file to ipfs
-
- set metadata file for widget
-
- refactor layouting mechanism to be able to register layouts from within the component. This enables us to use to save the state of the router in the Storage, Currently callbacks like onClick cannot be saved to Storage, which causes the state of the router to be lost when the page is refreshed.
- metadata support for widgets (not a pressing issue, can be done in the web-ui)
- purging of all widgets of a user
Later:
- VSCode extension for widget development (live preview, mocking of widgets)
Every smart contract in NEAR has its own associated account.
When you run yarn deploy
, your smart contract gets deployed to the live NEAR TestNet with a temporary dev account.
When you're ready to make it permanent, here's how:
near-cli is a command line interface (CLI) for interacting with the NEAR blockchain. It was installed to the local
node_modules
folder when you ran yarn
, but for best ergonomics, you may want to install it globally:
yarn global add near-cli
Or, if you'd rather use the locally-installed version, you can prefix all near
commands with yarn
Ensure that it's installed with near --version
(or yarn near --version
)
Each account on NEAR can have at most one contract deployed to it. If you've already created an account such as
your-name.testnet
, you can deploy your contract to near-blank-project.your-name.testnet
. Assuming you've
already created an account on NEAR Wallet, here's how to create near-blank-project.your-name.testnet
:
-
Authorize NEAR CLI following the commands it gives you:
near login
-
Create a subaccount (replace
YOUR-NAME
below with your actual account name):near create-account near-blank-project.YOUR-NAME.testnet --masterAccount YOUR-NAME.testnet
Use the CLI to deploy the contract to TestNet with your account ID.
Replace PATH_TO_WASM_FILE
with the wasm
that was generated in the contract
build directory.
near deploy --accountId near-blank-project.YOUR-NAME.testnet --wasmFile PATH_TO_WASM_FILE
On Windows, if you're seeing an error containing EPERM
it may be related to spaces in your path. Please see
this issue for more details.