Skip to content

Latest commit

 

History

History
120 lines (91 loc) · 4.23 KB

README.md

File metadata and controls

120 lines (91 loc) · 4.23 KB

Solidity-Examples

  • Follow the tutorials here : Truffle
  • Make sure Node.js & npm package manager is installed and accessible from the command line along with truffle.

Useful Links

Contracts

The running examples and vulnerable contracts are in contract-samples folder. See README.md Other folders contains token or full project examples that can be run for better understanding.

Running Examples

Make sure you have Ganache test blockchain running locally in your machine. Run *.AppImage with chmod a+x from the download site.

$ cd ballot-example

$ truffle compile
    ...
    Compiling your contracts...
    ===========================
    ✔ Fetching solc version list from solc-bin. Attempt #1
    > Compiling ./contracts/Address.sol
    > Compiling ./contracts/Ballot.sol
    > Compiling ./contracts/Migrations.sol

$ truffle migrate
    ...
    Compiling your contracts...
    ===========================
    ✔ Fetching solc version list from solc-bin. Attempt #1
    > Everything is up to date, there is nothing to compile.

    Network up to date.

$ truffle deploy
    ...

# For testing
$ truffle test
    ...
    Using network 'development'.


    Compiling your contracts...
    ===========================
    ✔ Fetching solc version list from solc-bin. Attempt #1
    > Compiling ./test/4_Ballot_test.sol
    ✔ Fetching solc version list from solc-bin. Attempt #1
    > Artifacts written to /tmp/test--288401-NgXp0VWd8kTu
    > Compiled successfully using:
    - solc: 0.7.6+commit.7338295f.Emscripten.clang



    Contract: Address
    [
    '0x53756d6974000000000000000000000000000000000000000000000000000000',
    '0x5261766900000000000000000000000000000000000000000000000000000000',
    '0x52616a616e000000000000000000000000000000000000000000000000000000',
    '0x5261676875000000000000000000000000000000000000000000000000000000',
    '0x45746865724b696e670000000000000000000000000000000000000000000000',
    '0x5368656b68617200000000000000000000000000000000000000000000000000',
    '0x436f6e74726163746f7200000000000000000000000000000000000000000000',
    '0x50756c75626b0000000000000000000000000000000000000000000000000000',
    '0x426974636f696e4b696e67000000000000000000000000000000000000000000',
    '0x44616f4865636b65720000000000000000000000000000000000000000000000'
    ]
        ✓ Should return 10 addresses (43ms)


    1 passing (184ms)

Other Commands

Smart contract functions to run on the MetaCoin-example folder.

$ truffle exec src/getAddress.js --network development --compile
$ truffle console
...
$ truffle(development)> let instance = await MetaCoin.deployed()
...
$ truffle(development)> let accounts = await web3.eth.getAccounts()
$ truffle(development)> instance.sendCoin(accounts[1], 10, {from: accounts[0]})
...
...
$ truffle(development)> .exit

Running Script

Logging and running each command from truffle console can be tedious. We can use a script (written in JavaScript) to execute on development network. See (truffle-run.js)

$ truffle exec ./example_run.js --network development
...

Using network 'development'.

0xdAd324Ac3f539785b8E02329fFd34e7657a16064
99713108700000000000
...