current position:Home>Tutorial: Build with Infura on Celo, an Ethereum Compatible Layer 1 Network

Tutorial: Build with Infura on Celo, an Ethereum Compatible Layer 1 Network

2022-11-24 12:10:22ConsenSys

Infura Happy to announce that will be Celo 网络添加到 Infura 平台.Celo 是一个与 EVM 兼容的第 1 层,Hope to accelerate social welfare through blockchain.它是 ReFi 或“再生金融”的主要参与者,The campaign utilizes Web3 解决气候变化、Social issues such as income inequality and biodiversity.

Since most of the world is operated using smartphones,因此 Celo Think of your phone as if it were in its network【一等公民】.Mobile crypto wallet Valora 最初是在 Celo 内部开发的,然后于 2021 年推出.

Celo The laudable goals mentioned above are supported by a number of initiatives and technical features,例如:

  • Use zero-knowledge proofs and carbon-negative proofs of stake (PoS) Consensus mechanism to reduce its environmental footprint.Celo carbon negative PoS 是通过与 Project Wren 的合作,This is achieved through daily compensation.
  • make sure low gas 费用,可以用 ETH、CELO 代币或 Celo Any of the native stablecoins(例如 cUSD、cEUR 或 cREAL)支付
  • By developing external projects Valora And emphasize mobile-optimized languages(如 React、React Native 和 Flutter),Prioritize mobile-first usage.

All these features make Celo Attractive to those looking to use blockchain for good.Are you ready to build on it?在本教程中,We'll show you how to use it Infura 和 Truffle 开始使用 Celo Composer How easy it is.到本文结束时,You will be able to deploy your smart contract to Celo Testnet and build React dapp 前端.

先决条件

在开始之前,你需要:

入门

使用 Celo Endpoints create new ones Web3 访问密钥

We will enable from create Celo new for endpoints Infura Web3 访问密钥(Formerly known as Project ID)开始.Our application will use this key pair Celo The network executes the transaction.以下是使用 Infura 执行此操作的方法(或遵循This getting started guide).

  • 登录Infura主页
  • Click the button on the right - 创建新密钥
  • from the popup modal:
  • 选择网络 → Web3 API
  • Type anything you like in the name field
  • 点击“创建”
  • 向下滚动直到找到 Celo
  • from the Network drop-down list,选择 Alfajores Testnet endpoint
  • Click the icon on the right to copy the content

输出应该是:

https://celo-alfajores.infura.io/v3/Please make a note of this,Because this will come in handy later in this tutorial.

Celo Composer

Celo Composer Provides simple templates to start developing.You can use it by following the steps in the readme file Celo Composer.

要使用 Truffle,You need to make some adjustments.

你有两个选择:

  1. 您可以Clone the original repository并取消注释 Truffle 行(此处此处此处

或者

  1. 你可以 fork A warehouse that we have already taken care of for you
Git clone http://www.github.com/cooganb/celo-infura-truffle

Testnet Funding

我们需要来自 Celo 的测试网 Alfajores some test funds.Get the one closest to you MetaMask developer account and Claim some free fun money.(with your permission,The test site site will Alfajores 添加到您的 MetaMask 帐户.If for some reason you don't get the prompt,请查看 Chainlist.)

Now we have some funds to work with,Let's deploy our contract to Celo 的测试网.We're going to do it in two different ways.首先,我们将使用 Infura 和 Truffle 命令行部署.接下来,We will use custom Infura 附加组件的 Truffle 仪表板.

部署合约

方法一:命令行部署

对于此演示,我们将为 Celo 编写一个基本的 Greeter 合约,The contract is already written and ready to go.我们正在使用 Truffle 来编译合约.确保已安装 Truffle,然后运行以下命令:

1.pngFor contract deployment,We need to create own Celo private key for the testnet funds and add it to the Truffle 目录中的 .env 文件中.

您还需要将 Infura Account information is added to the truffle-config 文件中.在这里填写;It is also shown below:

2.pngOnce the above details are ready,We can deploy the contract with the following command:

3.png

Assuming we have enough funds and we have set it up correctly truffle-config.js,We should see the contract deployed successfully in the terminal.

方法二:Infura + Truffle DashboardDeploy if you have already deployed the contract using the method above,则可以跳至“构建前端”

当然,There is more than one way to deploy a smart contract,So let's look at will Infura Added as a custom endpoint.Truffle 有一个很棒的功能,called a dashboard,All we need to do is make sure we use the one from the previous example MetaMask 帐户.这是一个很好的选择,We can use this to safely deploy our contracts,并能够从 Infura Dashboards track metrics.

首先,让我们将 Infura Celo 端点添加到 MetaMask.在 MetaMask 的“网络”设置下,点击“添加网络”:

4.png然后,Add network details,但使用来自 Infura 的特定 Celo RPC 端点:

5.png

单击“保存”,You can use support Infura 的 Alfajores The network endpoint is gone.Start in a new terminal with the following command Truffle Dashboard:

6.pngYou should see a browser window open.单击“连接钱包”And make sure you are using custom Infura Endpoint account:

7.pngOpen a new terminal and run the following command to deploy Greeter 合约:

8.png

Click on the transaction“处理”,它会提示 MetaMask 打开.

确认交易.Let's say you have the funds and everything goes well,The contract should be deployed.

构建前端

现在,Let's set up the front end of things. 我们将设置 React,但您也可以使用 React Native(有或没有 Expo)或 Flutter.进入 react-app packages 文件夹,Install dependencies and start the development environment:

9.png在浏览器中打开“localhost:3000”(Unless you changed the default port)并连接您的钱包.与以太坊不同,Celo There are many different wallet options,包括 Valora.这说明了 Celo The diversity of developments happening on the web.

Connect to your pass Alfajores after the funded account,您应该会看到以下内容:

10.png单击工具栏上的“0”索引,You will get information about our deployment Greeter contract information:

11.png

从这里,You can read or set values ​​from our contracts greet.试试看!

结论

这只是使用 celo-composer 在 Celo The beginning of the possibility of realization.If you want to build something using templates,请使用 npx @celo/celo-composer 并选择 react-with-tailwind 模板.Celo-composer More mobile-first languages ​​are also supported,例如 Flutter 和 React Native.

Celo There is also an exciting new feature coming soon,称为 SocialConnect,这是一种“An open-source protocol for creating proof-mapping off-chain identifiers”,例如手机号码、Twitter account or email address.它允许 Celo Users send money to these identifiers,Even if the users behind those accounts haven't Celo 账户.Once they log in and claim their ID,They can receive funds.

This is an innovative approach that could have a huge impact on the remittance industry,Because people can use SocialConnect Send money to friends and family in the form of stablecoins.

所有这些都说明了 cLabs、Celo 基金会和 Celo 协议的重点,Namely bringing blockchain efficiencies to places where financial and environmental assistance is most needed、Inclusiveness and other benefits.Infura 很高兴与 Celo 一起努力.要开始在 Infura 上使用 Celo 进行构建,Sign up for a free account now.For more technical documentation,请访问我们的文档.

原文链接: https://blog.infura.io/post/tutorial-build-with-infura-on-celo

本文首发于:https://mp.weixin.qq.com/s/5-5PWJROA1p_LUc1a3cqzg

copyright notice
author[ConsenSys],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/328/202211241159422841.html

Random recommended