Deploying your first production EOS DAPP

in eos •  10 months ago

EOS Asia

The article is written by EOS Asia, Asia's most technical and international EOS Block Producer Candidate that ranked top 21 block producers upon EOS' mainnet launch.

code_coder_communication.jpeg

Given the successful release of the EOS mainnet, we’re ready to deploy our smart contract to the production blockchain and officially release our first DAPP. In this tutorial we’ll move our smart contract environment from a self-hosted development setup to the EOS mainnet, working on the smart contract developed in our previous tutorial Getting started with EOS development: Ping.

Setting up local command line tools

One of the pre-requisites of working with any EOS blockchain are the tools used to communicate with the blockchain itself. For EOS, the only tools you need installed are cleos which acts as the command line interface to talk with the EOS blockchain and eosiocpp to compile your smart contract from C++ to Web Assembly.

Connecting to the EOS Mainnet

After we’ve installed the tools required to talk with the EOS blockchain, it’s time to actually talk to it. Since we’ll be deploying to the EOS mainnet, we’ll have to configure our endpoint to point to a production node, in this case, the API endpoint provided by EOS Asia:

$ cleos -u https://api1.eosasia.one/ get info

{
  "server_version": "c9b7a247",
  ...
}

The output should include some details about the chain, server_version, head_block_num … If so, your setup is working correctly and we’re ready to start the logistics of deploying our smart contract!

Creating a smart contract sub-account

As of this writing there’s no way to create an account on the EOS mainnet, so you must have purchased EOS in the pre-sale and had your account imported. It’ll require about 1.4 EOS to complete. This section will go through creating a sub-account to deploy your smart contract.

Throughout the tutorial, I’ll refer to the main account as EOSDev and the account created to deploy the smart contract as EOSPingCt.

Step one: Create a new set of keys

$ cleos create key
Private key: 5JbygCJkPHK8Udx6bLq9T56f1t...
Public key: EOS6K5fLNkxWhX8sgUNaH7eAHVkXMTuFv...

Be sure to keep the private key in a secure location. Losing this means you’ll lose access to your wallet and consequently the ability to update your smart contract in the future.

Step two: Unlock your main account’s wallet

$ cleos wallet unlock

This step is necessary to both create a sub-account and send some EOS to fund the wallet’s smart contract deploy.

Step three: Creating the account

$ cleos -u https://api1.eosasia.one/ system newaccount --stake-cpu "0.2 EOS" --stake-net "0.2 EOS" --buy-ram-kbytes 4 EOSDev EOSPingCt {public_key} {public_key}

We’ll stake some EOS for networking and CPU and buy 4KB of RAM in this demo. Don’t forget to replace {public_key} with the actual public key generated from step 1!

This step will take a few minutes to go through the network. Give it 3-5 minutes before moving onto step four.

Step four: Fund the account

cleos -u https://api1.eosasia.one/ transfer EOSDev EOSPingCt "1.0 EOS"

Finally, we fund the new account with some EOS.

Deploying the smart contract

Note: If you haven’t gone through compiling the ping web assembly file, please check out this tutorial.

Now that we have our account setup on the EOS mainnet, we’re ready to deploy our smart contract. Let’s ensure we have our abi and wasm file generated from the ping tutorial, this tutorial assumes the following directory structure:

└── ping
    ├── ping.abi
    ├── ping.cpp
    └── ping.wast

1 directory, 3 files

The first order of business is to name the contract and upload the contract bundle:

$ cleos -u https://api1.eosasia.one/ set contract ping.code ./ping -p ping.code
Reading WAST/WASM from ./todo/todo.wasm...
Using already assembled WASM...
Publishing contract...
...

Once the deploy is processed and accepted by the block producers the smart contract is deployed to the EOS mainnet! This process takes a few minutes, but after it has completed anyone with a mainnet EOS account can run your smart contract, whether from the browser or from cleos. Let’s test it from our command line with the assumed EOSDev account we used above:

$ cleos push action ping.code ping '["EOSDev"]' -p EOSDev
executed transaction: 001d79b01f682cb0b084ff96df46743c718c0788eec6f1b5ae30416b36c282fd  231 bytes  102400 cycles
#  ping.code <= ping.code::ping           {"account":"EOSDev"}
>> Received ping

Congratulations, your ping contract is now on production! In our next tutorial, we’ll explore integrating a frontend with Scatter. As always, if you have any questions or run into any issues going through our tutorial please leave a comment or email me directly [email protected]

Socials
Telegram
Twitter @EOSAsia_one
Medium
Website
Steemit
Business: [email protected]
Tech: [email protected]

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!