love your life
love your life

Subscribe to feng

Subscribe to feng
<100 subscribers
<100 subscribers
Share Dialog
Share Dialog
在编写代码之前,您需要设置一个 Node.js 环境,推荐使用 replit ,它是一个基于 IDE 进行编程的浏览器。
1.在 repli 上注册一个免费帐户并登录;
2.点击左上角的create创建;
3.出现提示时选择 Node.js,然后点击Create Repl。
还需要一个以太坊节点来与 Facaster Registry 合约对话。 建议使用 Alchemy 。 如果您是第一次注册,以下步骤可能会略有不同:
1.注册 Alchemy.com ,并登录。
2.选择以太坊作为区块链,点击get started。
3.team name和app name随便取,网络选择Rinkeby,点击Create APP。
4.选择第一个免费的,点击continue。
5.点击跳过。
6.继续点击跳过。
7.点击continue。
8.随便输入什么,点击let‘s go。
9.点击view details。
10.点击view key。
11.找到HTTP的URL,复制v2/后面那部分代码,将其保存在某个地方。
12.切换回 Replit 并转到右侧窗格中的 Shell 选项卡并运行以下代码:
npm install ethers got@11.8.2
这将安装 ethers ,一个用于与 Ethereum 一起工作的库, got ,一个用于发出 HTTP 请求的库。 您可能会看到一些关于缺少 package.json 的警告,您可以忽略这些警告。
1.切换到 Replit 中心窗格中的 index.js 选项卡,然后复制下面的代码片段。 确保将那一堆×换成step1 的第11步保存的代码,点击run。
const { providers, Contract, utils } = require("ethers"); const got = require("got");
const doStuff = async () => { const ALCHEMY_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // Replace with your secret const provider = new providers.AlchemyProvider('rinkeby', ALCHEMY_SECRET);
const block = await provider.getBlockNumber();
console.log("The latest Ethereum block is:", block); }
doStuff();
2.当您点击运行时,如果一切正常,您应该会看到如下内容:
The latest Ethereum block is: 10027943
后面那个数字大家会不一样。
我们刚刚编写的代码创建了一个 Ethers Provider ,这是一个我们可以调用以与 Ethereum 交互的接口。 提供者通过 Alchemy 节点连接到区块链。
1.复制以下it代码并将其添加到底部 doStuff函数,就在最后一行的下方 console.log("The latest Ethereum block is:", block);. 所有后面的代码片段都应该以同样的方式添加到底部:
const REGISTRY_CONTRACT_ADDRESS = '0xe3Be01D99bAa8dB9905b33a3cA391238234B79D1' const REGISTRY_ABI = [ { name: 'getDirectoryUrl', inputs: [{ internalType: 'bytes32', name: 'username', type: 'bytes32' }], outputs: [{ internalType: 'string', name: '', type: 'string'}], stateMutability: 'view', type: 'function', }, { inputs: [{ internalType: 'address', name: '', type: 'address' }], name: 'addressToUsername', outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], stateMutability: 'view', type: 'function', }, ];
const registryContract = new Contract(REGISTRY_CONTRACT_ADDRESS, REGISTRY_ABI, provider);
const username = 'v'; const byte32Name = utils.formatBytes32String(username); const directoryUrl = await registryContract.getDirectoryUrl(byte32Name); console.log(${username}'s Host is located at: ${directoryUrl} \n);
2.如果一切正常,你会看到以下内容:
v's Host is located at: https://guardian.farcaster.xyz/origin/directory/0x012D3606bAe7aebF03a04F8802c561330eAce70A
在编写代码之前,您需要设置一个 Node.js 环境,推荐使用 replit ,它是一个基于 IDE 进行编程的浏览器。
1.在 repli 上注册一个免费帐户并登录;
2.点击左上角的create创建;
3.出现提示时选择 Node.js,然后点击Create Repl。
还需要一个以太坊节点来与 Facaster Registry 合约对话。 建议使用 Alchemy 。 如果您是第一次注册,以下步骤可能会略有不同:
1.注册 Alchemy.com ,并登录。
2.选择以太坊作为区块链,点击get started。
3.team name和app name随便取,网络选择Rinkeby,点击Create APP。
4.选择第一个免费的,点击continue。
5.点击跳过。
6.继续点击跳过。
7.点击continue。
8.随便输入什么,点击let‘s go。
9.点击view details。
10.点击view key。
11.找到HTTP的URL,复制v2/后面那部分代码,将其保存在某个地方。
12.切换回 Replit 并转到右侧窗格中的 Shell 选项卡并运行以下代码:
npm install ethers got@11.8.2
这将安装 ethers ,一个用于与 Ethereum 一起工作的库, got ,一个用于发出 HTTP 请求的库。 您可能会看到一些关于缺少 package.json 的警告,您可以忽略这些警告。
1.切换到 Replit 中心窗格中的 index.js 选项卡,然后复制下面的代码片段。 确保将那一堆×换成step1 的第11步保存的代码,点击run。
const { providers, Contract, utils } = require("ethers"); const got = require("got");
const doStuff = async () => { const ALCHEMY_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // Replace with your secret const provider = new providers.AlchemyProvider('rinkeby', ALCHEMY_SECRET);
const block = await provider.getBlockNumber();
console.log("The latest Ethereum block is:", block); }
doStuff();
2.当您点击运行时,如果一切正常,您应该会看到如下内容:
The latest Ethereum block is: 10027943
后面那个数字大家会不一样。
我们刚刚编写的代码创建了一个 Ethers Provider ,这是一个我们可以调用以与 Ethereum 交互的接口。 提供者通过 Alchemy 节点连接到区块链。
1.复制以下it代码并将其添加到底部 doStuff函数,就在最后一行的下方 console.log("The latest Ethereum block is:", block);. 所有后面的代码片段都应该以同样的方式添加到底部:
const REGISTRY_CONTRACT_ADDRESS = '0xe3Be01D99bAa8dB9905b33a3cA391238234B79D1' const REGISTRY_ABI = [ { name: 'getDirectoryUrl', inputs: [{ internalType: 'bytes32', name: 'username', type: 'bytes32' }], outputs: [{ internalType: 'string', name: '', type: 'string'}], stateMutability: 'view', type: 'function', }, { inputs: [{ internalType: 'address', name: '', type: 'address' }], name: 'addressToUsername', outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }], stateMutability: 'view', type: 'function', }, ];
const registryContract = new Contract(REGISTRY_CONTRACT_ADDRESS, REGISTRY_ABI, provider);
const username = 'v'; const byte32Name = utils.formatBytes32String(username); const directoryUrl = await registryContract.getDirectoryUrl(byte32Name); console.log(${username}'s Host is located at: ${directoryUrl} \n);
2.如果一切正常,你会看到以下内容:
v's Host is located at: https://guardian.farcaster.xyz/origin/directory/0x012D3606bAe7aebF03a04F8802c561330eAce70A
No activity yet