DEV Community

Madhav Jha
Madhav Jha

Posted on

Dev Setup for Crypto and AI

Create an EC-2 Instance for Devbox

  • A t2.medium should be fine. It has 2 vCPU and 4 GB memory and costs 0.0464 USD per hour. That is roughly $35 per month. A little steep but worth it.

  • For AMI, choose Deep Learning AMI GPU PyTorch 1.12.0 (Ubuntu 20.04) 20220913 (ami-08e2d37b6a0129927)

Install NodeJS

Source: https://github.com/nodesource/distributions/blob/master/README.md#debinstall

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - &&\
sudo apt-get install -y nodejs
Enter fullscreen mode Exit fullscreen mode

Another option is to first install node version manager.
Source: https://github.com/nvm-sh/nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

Check for LTS versions and install one of the latest ones.

nvm ls-remote
nvm install v16.17.1
nvm use v16.17.1
node -v > .nvmrc
nvm use
Enter fullscreen mode Exit fullscreen mode

Install Truffle

npm install -g truffle
truffle -v
Enter fullscreen mode Exit fullscreen mode

A simple project

mkdir fundraiser
cd fundraiser
truffle unbox react

Commands:

  Contracts: Compile:         cd truffle && truffle compile
  Contracts: Test:            cd truffle && truffle test
  Contracts: Migrate:         cd truffle && truffle migrate
  Dapp: Run dev server:       cd client && npm start
  Dapp: Test:                 cd client && npm test
  Dapp: Build for production: cd client && npm run build
Enter fullscreen mode Exit fullscreen mode

Remove existing files and create new ones

rm truffle/contracts/SimpleStorage.sol
rm truffle/migrations/1_deploy_simple_storage.js
rm -f truffle/test/*

touch truffle/contracts/Fundraiser.sol truffle/test/fundraiser_test.js
Enter fullscreen mode Exit fullscreen mode

Create a basic smart contract and a basic test file.

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract Fundraiser {}
Enter fullscreen mode Exit fullscreen mode
const FundraiserContract = artifacts.require("Fundraiser");

contract("Fundraiser", accounts => {
    let fundraiser;
    const name = "My Fundraiser";

    describe("initialization", () => {
        beforeEach(async () => {
            fundraiser = await FundraiserContract.new(name);
        });

        it("gets the beneficiary name", async () => {
            const actualName = await fundraiser.name();
            assert.equal(actualName, name);
        });
    });
});
Enter fullscreen mode Exit fullscreen mode

This test will fail initially. One can fix the failing test with the following changes.

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract Fundraiser {
    string public name;

    constructor(string memory _name) {
        name = _name;
    }
}

Enter fullscreen mode Exit fullscreen mode

At this point if you want to start a new project you may want to directly use this template: https://github.com/maddyonline/fundraiser. This template does above steps and leaves it at this stage.

If you clone the template, you can try running truffle test in truffle directory and you should be off to the races.

Top comments (0)