Skip to content

Instantly share code, notes, and snippets.

@morenoh149
Last active February 1, 2020 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morenoh149/4d28e63ffde803a5f50c0b516a7caa2b to your computer and use it in GitHub Desktop.
Save morenoh149/4d28e63ffde803a5f50c0b516a7caa2b to your computer and use it in GitHub Desktop.
Intro to smart contract programming in solidity Oct 2019

Intro to Smart Contract Development, Jan 2020

Agenda

  1. Go through slides https://github.com/MetaMask/IPFS-Ethereum-Hackathon/blob/master/slides/01_DanFinlay_intro_to_ethereum_blockchains/DanFinlay-intro_to_ethereum.pdf
  2. deploy ballot to test net
  3. go over solidity language
  4. deploy ico to test net
  5. build webapp with truffle
  6. (stretch) deploy bonding curve token https://github.com/yosriady/continuous-token

Lesson

  1. open https://remix.ethereum.org

Loading, Compiling, and not yet Deploying

Click the remix icon on the top of the icon panel to see the Landing Page.

In the Environments section, click the Solidity button.

In the icon panel, click file explorer icon.

Click ballot.sol & the file should appear in the main panel in a tab.

Click the solidity compiler icon solidity compiler icon.

Click the compile button compile ballot and watch it compile.

Deploying a contract

We've got a compiled contract.

Now we have to put that code on a simulation of a blockchain.

Click the Deploy and Run icon deploy & run icon. But before you click it, make sure that ballot.sol is the active tab.

Select the JavaScript VM from the Environment pulldown.

In the text box to the right of the Deploy button, put a number in this text box.

Click the Deploy button.

You have deployed the contract to the JSVM.

Install MetaMask.

Interacting with the functions in a deployed contract

Open up the contract by clicking the caret - so the caret points down.

There are 4 functions in this contract.

If this contract had imported other contracts then the functions of the imported contracts would be visible here too.

Blue buttoned functions are either pure or view functions.

Ballot.sol does not have a payable function. If it did the button's color would be red.

Deploying to a test net.

Click the MetaMask icon in your browser. Sign in and choose the rinkeby test network.

Get some test ETHER at https://faucet.rinkeby.io by pasting your address. (If you don't have twitter try the ropsten network and https://faucet.ropsten.be/).

Go back to Remix. In the deploy plugin, in the Environment pulldown, choose Injected Web3.

Deploy your compiled ballot.sol.

You'll see the MetaMask popup asking you to pay for the transactions.

Your transaction will be broadcasted to the test blockchain and included in the next mined block. Study the generated etherscan link.

Go through slides

https://docs.google.com/presentation/d/1HXrH5ymEmgJzmjM1Y1v14kq4gLjCvZCLI-EcnFmtSfA/edit?usp=sharing

deploy ico to test net

  1. copy https://github.com/bitfwdcommunity/ICO-tutorial/blob/master/ico-contract.sol into remix
  2. Go to Line 3–15 and look at the comment section. Although this is a comment section, this will help you down the track. The name of the template ICO is ‘bitfwd’ CROWDSALE token contract
  3. Change Line 4 to the title of your crowdsale.
  4. You will just change Line 6 after you deploy the contract on the Blockchain.
  5. Change Line 7’s Symbol to your respective coin name (Keep it short)
  6. Change Line 8 to the name of your token
  7. Go to Line 102 and change “bitfwd” to “(YourCrowdsaleName). DON’T USE SPACE OR IT WON’T WORK.
  8. Do the same for Line 118
  9. Go to Line 119 and change the symbol name, the same as the ones you did in the comment section
  10. Do the same for Line 120
  11. Leave Decimals at 18.
  12. On line 122 you will have to define you first ICO parameter, when does the bonus end?
  13. And on line 123, you will define when does the Crowdsale ends.
  14. go to line 212. On that comment, write what is the amount of tokens you will be giving away for ETH.
  15. On line 218, define how much people will get within the BONUS.
  16. On line 220, define how much people will get without the BONUS (the same ratio that you put on line 212). The “msg.value” is the amount of ETH that someone sent. So taking my contract as example, for every 1 ETH, i would give 1000 FWD in return.
  17. Now Under Compile→Choose the Token you are creating →Details
  18. Navigate to the build and deploy tab → Press Deploy Contract
  19. Click on the transaction tx or access https://ropsten.etherscan.io to check if the contract went through.
  20. Register this contract. To do that: In the Overview Tab → Click on the Contract Address
  21. Go to the Contract Code Tab → Click Verify and Publish
  22. Nearly there… The following steps are really important. So pay attention. Basically what we are doing here is trying to guarantee that the code fits what you saying you are deploying and registering this on the network. FOREVER.
  23. Be sure that the contract address field corresponds to the contract address that you have just deployed. Remember contract address is different to the MEW address you created so make sure not to get them confused
  24. The contract name has to match the one in the code, in my case is this: bitfwdToken. This was on Line 102 in your code
  25. To check which version of the complier, go back to the remix page where you got the BYTECODE from and look at the URL, the complier version will be there. In most cases it should be: v0.4.19+commit.c4cbbb05.js
  26. On Optimisation, choose No (We haven’t enable it before).
  27. On ENTER THE SOLIDITY CONTRACT CODE BELOW, copy the whole code from Remix, and paste in that area. NOT THE BYTECODE, but the code itself. Can also be copied from your text editor.
  28. *Remember to add on line 6 the contract address that has been generated!
  29. Now, leave the other fields in blank and click on Verify and Publish.

If you see a success page with green checkmarks you deployed your ico!

Resources

Tools

Truffle Setup

go through https://www.trufflesuite.com/tutorials/pet-shop

osx

windows

  • (any windows specific steps?)

For all students

  1. install nodejs https://nodejs.org/
  2. install an editor, I recommend https://code.visualstudio.com
  3. install the truffle suite $ npm install -g truffle
  4. install ganache
  5. install the chrome browser
  6. install the metamask chrome extension
  7. get test tokens for the Ropsten network via the faucet https://blog.bankex.org/how-to-buy-ethereum-using-metamask-ccea0703daec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment