An Extremely Simple Solidity Contract Development Workflow

Running a Solidity Contract on Truffle

If starting from scratch

  1. Install truffle: npm install -g truffle

  2. Create a new truffle project

    1. In an empty directory run: truffle init
  3. In truffle-config.js, uncomment the development network and change its port to 9545 (the port used for truffle develop)

  4. Write a new contract in ./contracts, something like ./contracts/WriteAndRead.sol

  5. Add a new migration file for deployment at ./migrations/2_deploy_contracts.js:

    var WriteAndRead = artifacts.require("WriteAndRead");
    
    module.exports = function(deployer) {
    	deployer.deploy(WriteAndRead);
    };

After doing the above, or if you've just cloned this repo and installed truffle

  1. Run truffle develop to start the local blockchain and enter the truffle console

  2. In another shell, run truffle migrate --network development to compile and deploy your contract onto your local blockchain. Note: This has to be done after the local blockchain is already running

  3. From within the truffle console, do something like let instance = await WriteAndRead.deployed()

  4. Run one of your contract's transactions with something like instance.writeUint(1234)

  5. Run one of your contract's calls with something like instance.getUint()

  6. Type .exit to leave the truffle console

References:

These links are of varying quality but I probably got a tidbit out of each of them since I have them all open in tabs right now: