欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Setting up Ethereum smart contract development using Parity on Ubuntu

程序员文章站 2022-07-15 09:40:44
...

Ethereum represents one of the most interesting technological developments in the past few years, taking the fundamental principles of a blockchain, and allowing executable “contracts” to be written. These contracts can be relatively simple but also incredibly powerful.

This post will walk you through setting up a development environment so that you can deploy and test your own smart contracts on the Ethereum test blockchain (“Ropsten”).

Installing Parity

Parity is a fast Ethereum browser, a tool which allows you to interact with the blockchain. On my laptop at least, it is significantly faster to synchronise and use than geth, which is probably the “standard” tool for interacting with the Ethereum blockchain.

To install for your platform, follow the instructions on the Parity site. If you use Mac OSX or Ubuntu, this is as simple as running the following command:

bash <(curl https://get.parity.io -Lk)

Connecting to the Ropsten testnet

To run Parity and connect to the testnet, use the following command:

parity — chain=ropsten

You’ll see a stream of stuff fly by in the terminal as Parity connects to the testnet, and starts the process of synchronising the blockchain. This might take a while…but rest assured it’s much faster than using the Ethereum Wallet app.

While you wait, you can still get started using Parity through its lovely web interface.

Setting up Parity

Parity comes with a really nice, fully featured web interface. This allows you to view and create wallets (where you keep your Ether), interact with other apps and to create or interact with Contracts.

By default, the parity web interface should be available at http://127.0.0.1:8180

Setting up Ethereum smart contract development using Parity on Ubuntu
The Parity web interface

When you first launch the web interface, it will guide you through creating a wallet. Use a strong password, but remember as this is on the testnet, the Ether you collect here aren’t anywhere near as valuable as “real” Ether.

Get some testnet Ether

To deploy and interact with a Contract on the blockchain (testnet or otherwise) you’ll need some Ether. Getting Ether on the testnet is a little easier than on the main blockchain, and there are a couple of options:

  • Try and find a working testnet faucet — you’ll enter your wallet address and (hopefully) receive some Ether
  • Ask nicely in the Ethereum gitter chat
  • Set up Ethminer to mine for some Ether

After a bit of time trying the first two options, I resolved to mine my own Ether, and it wasn’t too hard.

Setting up Ethminer

Ethminer is a separate tool which talks to the blockchain via Parity with the aim of validating the transactions that occur. As a reward for validating the transactions, you will occasionally receive some Ether. It’s not super quick to receive the Ether, but it’s pretty quick to setup, so I just left it for a few hours and came back to almost 100 Ether in my wallet. WooHoo!

To install in Ubuntu:

sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum ethminer

Now, to get everything hooked up, you’ll need to run a slightly modified Parity command. First, make a note of the wallet address you created in the web interface. Now restart parity using the following:

parity — chain=ropsten --rpc --author=<your_wallet_address>

Now in a new terminal window start ethminer:

ethminer -G

Note: The -G option enables GPU mining, which speeds it up. However, this does assume you have a suitable card and have set up your using the appropriate graphics card drivers etc. If it doesn’t work, try again without the -G.

Setting up Ethereum smart contract development using Parity on Ubuntu
Ethminer doing some mining

Again, you’ll see a wall of stuff stream past — this is ethminer starting to do its business. I left it for a few hours and came back to some Ether.

Writing a contract

Once you have some Ether, you can stop mining and start writing!

Parity has a built in contract development tool, which is pretty nice. Make sure you can see it by going first to the Settings in the Parity web interface and ensuring it is enabled.

Setting up Ethereum smart contract development using Parity on Ubuntu
Parity settings

Now you can go to the Contracts tab, hit the Develop button and you’re ready to go!

Setting up Ethereum smart contract development using Parity on Ubuntu
Developing an example smart contract

As for what to write, that’s for another article. You can get started with your own cryptocurrency and learning more about Solidity, one of the languages used to programme smart contracts. But you now have all the tools and some Ether!

原文地址:https://medium.com/@joshua_e_k/setting-up-ethereum-smart-contract-development-using-parity-on-ubuntu-abca4da3dce2