Browse Source

Fix cross-platform issues (Windows support)

master
Tal Kol 3 years ago
parent
commit
205e43cc9d
  1. 8
      .setup.glitch.sh
  2. 16
      README.md
  3. 0
      build/_build.ts
  4. 2
      build/_deploy.ts
  5. 20
      build/_setup.ts
  6. 8
      package.json

8
.setup.glitch.sh

@ -1,8 +0,0 @@
# this will download all dependencies for Ubuntu 16 (fift, func executables) and place them in ./bin
mkdir bin
wget https://github.com/ton-defi-org/ton-binaries/releases/download/ubuntu-16/fift -P ./bin
chmod +x ./bin/fift
wget https://github.com/ton-defi-org/ton-binaries/releases/download/ubuntu-16/func -P ./bin
chmod +x ./bin/func
wget https://github.com/ton-defi-org/ton-binaries/releases/download/fiftlib/fiftlib.zip -P ./bin
unzip ./bin/fiftlib.zip -d ./bin/fiftlib

16
README.md

@ -7,20 +7,22 @@
This project is part of a set of 3 typical repositories needed for a blockchain dapp running on TON blockchain:
* Smart contracts in FunC that are deployed on-chain (this repo)
* Web frontend for interacting with the dapp from a web browser
* Telegram bot for interacting with the dapp from inside Telegram messenger
* Web frontend for interacting with the dapp from a web browser (coming soon)
* Telegram bot for interacting with the dapp from inside Telegram messenger (coming soon)
## What does this repo contain?
* `contracts/*.fc` - Smart contracts for TON blockchain written in [FunC](https://ton.org/docs/#/func) language
* `build/build.ts` - Build script to compile the FunC code to [Fift](https://ton-blockchain.github.io/docs/fiftbase.pdf)
* `build/deploy.ts` - Deploy script to deploy the compiled code to TON mainnet
* `test/*.spec.ts` - Test suite for the contracts running on [Mocha](https://mochajs.org/) test runner
* `test/*.spec.ts` - Test suite for the contracts in TypeScript running on [Mocha](https://mochajs.org/) test runner
* `build/_build.ts` - Build script to compile the FunC code to [Fift](https://ton-blockchain.github.io/docs/fiftbase.pdf)
* `build/_deploy.ts` - Deploy script to deploy the compiled code to TON mainnet (or testnet)
* `build/_setup.ts` - Setup script to install build dependencies (used primarily for Glitch.com support)
There is no one official way to develop smart contracts for TON. Every developer has their own best practices. This setup is definitely opinionated and some developers may not appreciate the choices made. Nevertheless, we stand by every choice made here and believe that this is the optimal setup to develop fully tested contracts in the most seamless way possible.
Some of the opinionated choices made here include:
* Cross platform support - allow developers to work on Mac M1, Mac Intel, Windows or Linux
* Strong belief in tests - contracts often manage money - they must be developed under high scrutiny
* Clear and documented code to help users audit the contracts sources and understand what they do
* Reliance on modern TypeScript to develop clean and typed scripts and tests in a modern framework
@ -50,7 +52,7 @@ Once your local machine is ready, install the project:
* Git clone the repo locally and rename the directory to your own project name
* In the root repo dir, run in terminal `npm install`
### or.. work online instead
### or.. work 100% online instead
Alternatively, you can ignore the above requirements and develop right inside a web browser with an online IDE and *zero* setup. Simply open this repo inside [Glitch](https://glitch.com/) without installing anything:
@ -89,7 +91,7 @@ Alternatively, you can ignore the above requirements and develop right inside a
* Make sure all contracts are built and your setup is ready to deploy:
* Each contract to deploy should have a script `build/mycontract.deploy.ts` to return its init data cell
* The deployment wallet is configured in `.env` (created automatically if not exists), with contents:<br>
`DEPLOYER_MNEMONIC="mad nation chief flavor ..."`
`DEPLOYER_MNEMONIC="mad nation chief flavor ..."` (24 secret words)
* To deploy to mainnet (production), run in terminal `npm run deploy`
* To deploy to testnet instead (where TON coins are free), run `npm run deploy:testnet`
* Follow the on-screen instructions of the deploy script

0
build/build.ts → build/_build.ts

2
build/deploy.ts → build/_deploy.ts

@ -23,7 +23,7 @@ async function main() {
console.log(`Deploy script running, let's find some contracts to deploy..`);
// check input arguments (given through environment variables)
if (process.env.TESTNET) {
if (process.env.TESTNET || process.env.npm_lifecycle_event == "deploy:testnet") {
console.log(`\n* We are working with 'testnet' (https://t.me/testgiver_ton_bot will give you test TON)`);
} else {
console.log(`\n* We are working with 'mainnet'`);

20
build/_setup.ts

@ -0,0 +1,20 @@
// This is a simple setup script in TypeScript that should work for most projects without modification
// The purpose of this script is to install build dependencies (tools like "func" and "fift") automatically
// We rely on this script for example to support Glitch.com (online IDE) and have it working in one click
import fs from "fs";
import child_process from "child_process";
// check if we're running on glitch.com (glitch is running Ubuntu 16)
if (fs.existsSync("/app/.glitchdotcom.json")) {
// make sure we're installed once
if (!fs.existsSync("/app/bin")) {
child_process.execSync(`mkdir bin`);
child_process.execSync(`wget https://github.com/ton-defi-org/ton-binaries/releases/download/ubuntu-16/fift -P ./bin`);
child_process.execSync(`chmod +x ./bin/fift`);
child_process.execSync(`wget https://github.com/ton-defi-org/ton-binaries/releases/download/ubuntu-16/func -P ./bin`);
child_process.execSync(`chmod +x ./bin/func`);
child_process.execSync(`wget https://github.com/ton-defi-org/ton-binaries/releases/download/fiftlib/fiftlib.zip -P ./bin`);
child_process.execSync(`unzip ./bin/fiftlib.zip -d ./bin/fiftlib`);
}
}

8
package.json

@ -7,10 +7,10 @@
"scripts": {
"prettier": "npx prettier --write '{test,contracts,build}/**/*.{ts,js,json}'",
"test": "mocha --exit test/**/*.spec.ts",
"build": "ts-node ./build/build.ts",
"deploy": "ts-node ./build/deploy.ts",
"deploy:testnet": "export TESTNET=1 && ts-node ./build/deploy.ts",
"postinstall": "! test -f /app/.glitchdotcom.json || test -d /app/bin || bash .setup.glitch.sh"
"build": "ts-node ./build/_build.ts",
"deploy": "ts-node ./build/_deploy.ts",
"deploy:testnet": "ts-node ./build/_deploy.ts",
"postinstall": "ts-node ./build/_setup.ts"
},
"devDependencies": {
"@swc/core": "^1.2.177",

Loading…
Cancel
Save