Eosio-cpp -abigen -o Hello.wasm Hello.cpp Error Reading Hello.cpp
How to Deploy and Run a Smart Contract on the EOS Blockchain
Nosotros are going to write a simple smart contract and deploy it to EOS.
More and more dapp are now being built on EOS, and at the heart of every dapp is the smart contract: programs that run on the blockchain. When I was learning the ropes effectually EOS the best guide bachelor to me was the EOS official developer portal: https://developers.eos.io/, however, afterwards compiling the smart contract locally I had limited resources to reference for guidance on deployment on a live surround. Due to this setback, I was challenged to doing more research and findings, and in the procedure, Eureka!, I constitute several efficient means in getting things done. Hence, I decided to write this guide for everyone first their journey into blockchain evolution and EOS.
Prerequisites:
- Install binaries: https://developers.eos.io/eosio-home/docs/setting-up-your-environment
- Install the Contract Development Toolkit: https://developers.eos.io/eosio-home/docs/installing-the-contract-development-toolkit
EOS Smart Contract
Allow'south take a look at a simple smart contract for EOS.
This is a simple contract written in C++ and it's comprised as a single file named how-do-you-do.cpp. Ordinarily, for a smart contract, there would be 2 files: the header file .hpp file extension and the principal file .cpp. The header file is usually where y'all declare all the public variables and methods of the contract that can be accessed from the outside, nevertheless for the sake of simplicity let'due south just piece of work with a simple contract that just consists of one master .cpp file.
A glance at the code shows only ane method in the class named hi (methods are called actions in EOS by the mode). We want to be able to phone call this method on the blockchain and then we put the [[eosio::activeness]] tag above it. Its input is the user and all it does is prints out that input when called upon. Go ahead and burn up VS Lawmaking (or your favorite code editor), blazon the code in and save it as hello.cpp
EOS Compiler
At present that we have written our elementary contract allow's compile it. EOS compiler compiles your source code (.cpp and .hpp) to web assembly format (.wasm). It besides has the option to generate an ABI file (.abi) for your contract. Now y'all tin think of the wasm file every bit an executable programme and the abi file as a description of how to talk to that program.
Fire up your terminal and navigate to your directory that y'all saved the howdy.cpp file. Blazon the to a higher place command to compile and generate the abi besides. Yous should now run across three files in your directory.
EOS Account
We now have the files required to deploy our simple smart contract which is the hello.wasm and hello.abi but to be able to deploy information technology we volition crave an account on EOS. I am going to bear witness you how to deploy information technology on the EOS Testnet just the steps required to deploy it on the Mainnet are similar. The first step now is to create an account on a Testnet, we are going to exist using the CryptoKylin Testnet. If you become to their site: https://world wide web.cryptokylin.io, you will detect a link on creating an business relationship, simply you will be required to download and gear up a Besprinkle wallet. I have found a faster way to create an business relationship, open up your browser, and head to https://dev4eos.com.
Click on the TestNet button on the superlative right, select an Endpoint with the fastest speed. Write down this endpoint URL somewhere, we will be using it throughout this guide. Now enter a 12 graphic symbol business relationship name under Create Account, in my example, I entered "youraccname1". Click on Create Business relationship button and you will get a like JSON string returned.
Save this string somewhere, because we are going to need the keys to deploy our smart contract latter. Now click on the Faucet button to become free EOS Tokens (yes similar costless beer).
To ostend your business relationship has been created and credited with the free tokens:
If you would like to deploy a smart contract on the Mainnet then you lot would demand to create an account there. I created my business relationship using https://eos-account-creator.com
Now that you lot have gear up an business relationship, I volition work you lot through the fundamentals of the EOS account.
An EOS account is a gear up of private and public keys. When we created the account earlier we were given ii sets of public-private keys. These 2 sets are the Owner and Active keys. The exercise is to keep your Owner key far and condom somewhere and utilise your Active key to do all the transactions on the blockchain. If you accidentally lose your Agile key, you tin and so use your Owner key to take back command of your business relationship. For the remainder of this guide, nosotros will be using your Active cardinal only.
EOS Wallet
We will be using the wallet that comes with the EOS binaries which is accessible by the command-line tool cleos. Open Terminal and type the start line below:
We have just created a wallet called kylin1, delight save this password so that we can unlock this wallet in the hereafter. After creating this wallet, it has been locked automatically so let's unlock it. Enter the password when prompted.
Remember nosotros are now in possession of the Agile and Possessor keys afterward creating an business relationship in the previous section. Open up the JSON I asked you to save earlier. Try to locate your "active_key" and look for the private field inside its brackets that looks like this:{"individual": "5Hup7GxQ8aNE4HhfLUt4Rb7SN5E7yx2onrJYsg4DFG2qZ3gntwa"}.
Okay done! Give yourself a big pat on your back. We take created a wallet chosen kylin1 and imported our Active private central into it.
NOTE: We do not need to import the public fundamental because it will be autogenerated from the private key.
Deploying an EOS Smart Contract
Fourth dimension to deploy! Bring out the guns and the tanks.
Nosotros have all the requirements to deploy our smart contract:
- Compiled .wasm
- .abi
- Testnet account with sufficient funds
- Wallet with Testnet account key
Unlock your wallet over again and enter the password once prompted. Now blazon in the command on the start line below, supercede '/Users/shankar/contracts/hello' with the path to your hello.wasm directory.
Oh no! why won't it deploy my contract? well if you read the Error Details you will see that your account has bereft ram. This is how EOS works, you need ram to deploy. Allow's go buy ourselves some RAM
Ok now we have enough ram, so let's attempt to deploy again.
Success! Call up to supersede '/Users/shankar/contracts/how-do-you-do' with the path to your hi.wasm directory. To go your path, you can cd into your directory and blazon pwd on the terminal to print out your full path.
If you are getting this error please continue on trying, and also check that the path to your wasm file is right.
Executing our EOS Smart Contract
Now that we have our babe deployed and alive on the blockchain, let's go alee and execute the hi method on our smart contract.
You will now meet that your hi method has been executed and a transaction hash is returned. Hurray! we made it. I am so proud of you for accomplishing your showtime step towards the futurity of decentralization. We are the soldiers building the infrastructure and applications step by step, chip by chip that will power a fully decentralized economy thus unlocking tremendous prosperity to all people on earth.
Note: To deploy and run your smart contract on the Mainnet simply replace our testnet URL ( https://api.kylin.alohaeos.com:443 ) with any of the API endpoints of the main 21 cake producers. https://www.eosdocs.io/resources/apiendpoints/
This is my first fourth dimension writing on Medium and I hope you enjoyed this. Possibly next time I will write on how to connect React or Vue frontend to a smart contract.
What's Next
At present that you have a simple Smart Contract running on EOS, how about we connect it to a simple Front Cease. I have just finished writing about this, click here to view the article.
Follow me on my LinkedIn!
Source: https://medium.com/@shankqr/how-to-deploy-and-run-a-smart-contract-on-the-eos-blockchain-from-zero-to-hero-72ca592803ba
0 Response to "Eosio-cpp -abigen -o Hello.wasm Hello.cpp Error Reading Hello.cpp"
Post a Comment