How to code smart contract without Mist

in #ethereum6 years ago

For the lest few weeks I've been using Mist on my Mac trying to get it work so I can code a smart contract. I spent weeks trying to fully sync the Mist. I was losing peers regularly every day, so deploying or testing the contract took days. It is very buggy, I had to remove the whole database, resync it, wait for peers, then lose them again, work only for few minutes per day... I was losing my mind. After a while I figured that I can use "light client" so Mist doesn't sync the whole network >50GB on my laptop. It kinda worked, but still the problem remained. I was losing peers, couldn't sync fully, couldn't test or deploy my contract...

▶▶▶Be sure to take a look at MimiCoin ICO!◀◀◀

Let me show you how I solved my problem!

Solution

MyEtherWallet + Ethereum Remix! *In this tutorial I'll use Remix's default contract and fake ether wallet. **Always save your code on git so you can compile it on Remix. ***Keep your Remix environment opened while working on this tutorial.

Step 1

Write your own contract and visit https://remix.ethereum.org. Like I said I'm gonna use Remix's default contract called ballot.sol. Paste your code into Remix and click on "Start to compile"

Step 2

When you successfully compile your code click on "Details" button and pop up will open up. Remix "Details" popup. In order to deploy contract via MyEtherWallet you'll need Bytecode. What you need is to copy "object" part of BYTECODE section:

Step 3

Once you have that go to https://www.myetherwallet.com/, switch to Ropsten network (that is testing network where you can get free Ethers, check my article "How to get free ethers on Ropsten network" - coming soon!) and click on "Contracts".

Step 4

Copy your bytecode from step 2 into "Byte Code" textarea. It will automatically calculate the gas. Now choose your method of accessing the wallet. For this network purposes I just private key since it doesn't matter, it's test network. Once you accessed your wallet (this is because you need to pay a fee to deploy a contract) this screen will show and all you need is to sign transaction and deploy the contract. My contract has been successfully deployed, now you just need to wait for few minutes until it becomes available. If you go to: https://ropsten.etherscan.io/ and look for your wallet address you used to deploy the contract you'll find more info there. Here is my address and you can see that my contract has already been deployed:

Step 5

Now you can interact with the contract. Go back to your Remix environment and copy your ABI code. ABI is something like API for contracts in JSON so you can interact with your contract. **I advise you not to give that to anyone. **If you closed Remix don't worry, just do step 1 and 2 all over again and that's it. Open popup in Remix (from step 2), just click on "Details" button. Find **ABI, **it's just below BYTECODE: Here how it looks:

[ { "constant": false, "inputs": [ { "name": "to", "type": "address" } ], "name": "delegate", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "winningProposal", "outputs": [ { "name": "_winningProposal", "type": "uint8" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [ { "name": "toVoter", "type": "address" } ], "name": "giveRightToVote", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "name": "toProposal", "type": "uint8" } ], "name": "vote", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "name": "_numProposals", "type": "uint8" } ], "payable": false, "stateMutability": "nonpayable", "type": "constructor" } ]

Step 6

Go to https://www.myetherwallet.com/#contracts and click on "Interact with Contract". Enter the address of your contract and below that enter your ABI. All you have to do now is to choose function you coded you wish to access. If your contract is different and you have different functions there then you'll see different dropdown options. In order to do anything with contract you need to access your wallet because of fees. That's it folks! Be careful when creating a contract. Here are some starting points: https://digitalnomad.community/smart-contracts/ https://github.com/OpenZeppelin/zeppelin-solidity https://github.com/TokenMarketNet/ico

Coin Marketplace

STEEM 0.23
TRX 0.12
JST 0.030
BTC 66884.44
ETH 3466.52
USDT 1.00
SBD 3.19