Skip to content

Commit

Permalink
Add Ethereum & GoChain content
Browse files Browse the repository at this point in the history
  • Loading branch information
harishraisinghani committed Jul 23, 2019
1 parent f9b4f10 commit b0af08a
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 1 deletion.
76 changes: 75 additions & 1 deletion README.md
Expand Up @@ -29,7 +29,7 @@ Welcome to the Link Homepage! A few things to note here:

Since smart contracts deployed onto a blockchain are generally immutable (i.e. can NOT be changed), every time you make a change to the smart contract code in the Link IDE, effectively a new smart contract is being deployed which means a new `Client ID` and `Client Secret` will be generated for authentication.

> Try it! Here is a simple smart contract code for assigning ownership of an asset. **Delete** the `Demo` contract code and **copy and paste** the following code into the Link IDE and see what API endpoints are generated (note: it may take a few seconds for the change to persist):
> Try it! Here is a simple smart contract code (from `Ownership.sol`) for assigning ownership of an asset. **Delete** the `Demo` contract code and **copy and paste** the following code into the Link IDE and see what API endpoints are generated (note: it may take a few seconds for the change to persist):
```
pragma solidity ^0.5.8;
Expand Down Expand Up @@ -91,6 +91,80 @@ Let's walk through the process for deploying and setting up our Ownership smart

#### Using Ethereum Ropsten with Link

##### Setup

> First, setup an account on Infura, which provides easy-to-use APIs to interact with the Ethereum network without running your own Ethereum node. Register for an API key at https://infura.io/register and then create a project. You will then be able to access URLs containing your API key for the Ethereum Mainnet and all Testnets such as Ropsten which we will be using.
![Infura Setup](images/infura.png)

> Now seed your Link account wallet with test ETH from https://faucet.ropsten.be/ (1 ETH will be dripped to your wallet), which will be used to pay for transactions on the Ropsten testnet. You can find your Link account wallet address from the Ethereum Account menu as shown:
![Ethereum Account Link](images/ethereum_account_link.png)

![Ropsten Faucet](images/ropsten_faucet.png)

**Note: This Ropsten Faucet tracks the IP of the source making the request. On a common WiFi network, multiple requests from the same external IP will trigger the IP to be grey-listed for 24 hours. If so, connect your laptop to a different WiFi network or temporarily connect to a phone's WiFi hotspot when making the request**

##### API project setup in Link

> 1. In Link, open up the setting dropdown menu and select *`New Project`* which starts the new project wizard.
![Link New Project](images/link_new_project.png)

> 2. Under *Which contract would you like to use?*, select `Ownership` which we created in Part 1.
> 3. Under *Which Ethereum account would you like to use?*, use the *`Default Account`*. This is the account we seeded earlier with test ETH.
![Default Link Account](images/default_account_link.png)

> 4. Under *Which network would you like to use?*, select *`Create new`* and call it `Ethereum Ropsten Testnet`. Keep the *Block Confirmations Needed* at 0. Press *`Save`* and *`Next`*.
> 5. Under *Which connector would you like to use?*, select *`Create new`*. Call this connector `Infura Ropsten Connector` and use the URL for the Ropsten network from Infura (e.g. https://ropsten.infura.io/v3/182b941b70e6443b8854cc53786a3007). Ensure the *Network* selected is *`Ethereum Ropsten Testnet`*. Press *`Save`* and *`Next`*.
![New Ropsten Connector Link](images/ropsten_connector_link.png)

> 6. Now we just need to label our Deployment. Under *Where is your contract deployed?*, select *`Create new`*. Call this deployment `Ownership Ropsten Testnet Deployment`. Since we do not have **an existing contract deployment on Ethereum**, leave the *Address* field blank. Ensure the *Account* is the `Default Account`, the *Contract* is the `Ownership` contract and the *Network* `Ethereum Ropsten Testnet`. Press *`Save`* and *`Next`*.
![Ethereum deployment Link](images/ropsten_deployment_link.png)

> 7. Now we're ready to deploy our contract to the Ethereum Ropsten Testnet. Press `Deploy` and you should get a deployment in progress indicator icon. This might take a few seconds to complete. If deployed correctly, you'll proceed to the next step to setup your API.
![Ready to Deploy in Link](images/ready_deploy_ropsten_link.png)

> 8. Now we label our Ownership contract API. Under *Name*, call it *`ownership-ropsten-testnet`* Also add in a human-readable display name. Ensure you are using the correct *Contract Deployment*. Press *`Save`* and *`Next`*.
> 9. Now we label our Ownership API **Consumer**. This would normally be the name of the app or service calling the API. For example, let's call the consumer `Collectible Stamps App Ropsten`. Ensure you are using the correct *API* and *Account*. Press *`Save`* and *`Next`*.
![Link Consumer New](images/link_consumer_ropsten.png)

> 10. Lastly, your consumer needs to authenticate with the Ownership API. A OAuth2.0 Client Secret is automatically generated. Ensure you are using the correct Principal/Consumer. Press *`Save`*, *`Next`* and then *`Finish`*.
![Create new OAuth](images/oauth_link_new.png)

Once you hit *`Finish`*, you should see your Ownership API documentation. Note the `client_id` and `client_secret` under *Authentication* which you will later use in your front-end app.

![API Documentation Link](images/ropsten_api_doc.png)

Let's also check that our Ownership contract deployed correctly on the Ethereum Ropsten Testnet. Click on the `Ethereum Contract Deployments` menu item to see a list of contract deployments and their addresses. Copy and paste the address of the `Ownership Ropsten Testnet Deployment` into the Ropsten Testnet explorer https://ropsten.etherscan.io to see the details of your contract deployment.

![Link Contract Deployments List](images/link_contract_deployments_list.png)

In the above example, the contract address on Ropsten Testnet is `0x5d81167993cb26e25e60be9deb58aab0fe93eccc`.

![Ropsten Explorer](images/ropsten_explorer_contract.png)

And we see our contract deployed on the Ropsten Testnet!

Now you can go ahead and use the API endpoints which are linked to the Ownership smart contract deployed on Ethereum Ropsten!

**Note:** If you want to deploy on the Ethereum Mainnet, just follow the same steps. The only difference is that you will need to:
* > Acquire actual ETH to send to your Link wallet
* > Use the Infura Mainnet URL
##### Deploying to GoChain
The process for deploying to GoChain (the Testnet or Mainnet) is also very similar. Just follow the same steps as above with only the following differences:

* > Ask for some free testnet GO in GoChain's [Testnet Telegram](https://t.me/gochain_testnet) to be sent to your Link account
* > For your Link Network Connector, use the appropriate [GoChain Network RPC URL](https://github.com/gochain-io/docs#network-rpc-urls)
Now you can run a front-end app using multiple blockchains with Link by simply using the appropriate set of API credentials that you setup in your front-end app! Link, with its inter-operability feature, opens up the ability for developers to **pick and choose what information to record on what blockchain**, depending on the desired benefits, versus having to pick and chose a specific blockchain and tech stack!
14 changes: 14 additions & 0 deletions contracts/Ownership.sol
@@ -0,0 +1,14 @@
pragma solidity ^0.5.8;

contract Ownership {
mapping(string => address) public ownerOf;
address public authority;

constructor() public {
authority = msg.sender;
}

function setOwner(string memory asset, address owner) public {
ownerOf[asset] = owner;
}
}
Binary file added images/default_account_link.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ethereum_account_link.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/infura.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/infura_api_key.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/link_consumer_ropsten.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/link_contract_deployments_list.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/link_new_project.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/oauth_link_new.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ready_deploy_ropsten_link.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ropsten_api_doc.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ropsten_connector_link.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ropsten_deployment_link.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ropsten_explorer_contract.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ropsten_faucet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b0af08a

Please sign in to comment.