NEAR开发者认证 NCD - Day1

Day1课程

官方课程链接: https://learnnear.club/lessons/day-1-reading-web3-ncdl1c4/
https://hackmd.io/@nearly-learning

学习web 3

学习阅读控制金钱,身份和所有权的合约。

今天的目标是阅读尽可能多的合约。

有时人们不确定如何完成此活动。 这些技巧可能会有所帮助。

Try to figure out how to get to the contract code. Then move to quickly read the code. You want to see as much as you can. Ask yourself about the “purpose” of the contract (why is it?) and “code” (what is it?)

尝试弄清楚如何获得合约代码。 然后移动以快速阅读代码。 您希望看到尽可能多的东西。 问问自己合约的“目的”(why is it?)和“代码”(what is it?)

  • AssemblyScript合约 是以.ts结尾的文件,通常是main.ts或index.ts
  • Rust合约 始终位于名为lib.rs的文件中。

核心活动:

  1. 在进行其他操作之前,请先观看此视频
  2. 在下面的资源部分中,选择AssemblyScript或Rust
    查看您的语言标记为“CORE Activity”的所有3份合约

奖励活动:
clone所选语言的 starter 库并按照说明进行操作

  • AssemblyScript
  • Rust (still under development)

Remember to focus on READING and avoid the temptation to build and run everything along the way because it’s a distraction at this point. You can build and run everything tomorrow.
你阅读得越多越好,如果可以的话,继续读下去。记住要把注意力集中在阅读上,避免一路上构建和运行所有东西的诱惑,因为这会分散你的注意力。你明天就可以建立和运行一切。

Read ALL the contracts for your language of choice, not just 3
阅读你所选择的语言的所有合约,而不仅仅是3种

Read all the contracts from the OTHER language as well.
还要阅读其他语言的所有合约。

Check out these little puzzles, they may be fun for you
查看这些小难题,它们可能对您很有趣

Going Deeper
If you’re feeling fearless, here’s about as far as you might take this road in a day

Review all core-contracts and watch related Live Contract Review videos
Review Illia’s contract repo
Review all Rainbow Hackathon contract submissions

资源

记住:今天的活动

  • 您无需构建和测试每个合同
  • 您无需了解每一行代码
  • 您应该像看艺术或听音乐一样简单地阅读合约,而不必担心每个点或内容

AssemblyScript

如果您打算专注于AssemblyScript,请打开AssemblyScript合约列表

您应该至少阅读3个标记为CORE活动的合约。
在这里插入图片描述

Rust

如果您打算专注于Rust,请打开Rust合约列表

您应该至少阅读3个标记为CORE活动的合约。

您可以阅读有关Rust合约基础的更多信息,也可以观看视频
在这里插入图片描述

阅读 web3 任务

Please submit:

  • Contract name
  • What did you find most excited about it
  • What is the most challenging par to understand

根据原文提醒,填写如上信息到原文表单中,提交,任务完成。


相关项目如下:

NameNotesCode
SputnikDAOThis contract is a simple version of a DAO to give out tips, bounties and grants. Allows anyone to send a proposal to reward other people with funds and get a council to vote for it. The major difference between this and Moloch DAO design is that this contract would receive its function via donation and council has equal rights.https://github.com/VitalPointAI/SputnikDao-AS-Contract/tree/main/sputnikdao-as
MultisigThis contract provides a multisig scheme that allows making transfers, calling functions and adding / removing keyshttps://github.com/VitalPointAI/Multisig-Contract
WhitelistThe purpose of this contract is to maintain the whitelist of the staking pool contracts account IDs that are approved by NEAR Foundation.https://github.com/VitalPointAI/Whitelist-Contract
CounterThis contract implements simple counter backed by storage on blockchain.https://github.com/near-examples/counter
Guest BookSign in with NEAR and add a message to the guest bookhttps://github.com/near-examples/guest-book
Cross Contract CallsThis repo is organized around a series of lessons about making cross contract callshttps://github.com/near-examples/cross-contract-calls
NEAR Collection ExamplesThis repository serves to demonstrate differences in gas consumption when storing or retrieving data from the NEAR blockchain using AssemblyScript collection methods found in near-sdk-as.https://github.com/near-examples/collection-examples-as
NEAR AssemblyScript WorkshopThis workshop includes several activities that introduce the basic concepts of writing contracts for NEAR Protocol using AssemblyScripthttps://github.com/near-examples/workshop–exploring-assemblyscript-contracts
NEAR Ice CreamThis dApp demonstrates buying ice cream with NEAR tokenshttps://github.com/near/near-icecream
Crypto CorgisThis dApp is an implementation of Crypto Kitties for NEARhttps://github.com/nearprotocol/corgis
SputnikDAO FactoryThis contract is a factory that creates instances of SputnikDAOhttps://github.com/VitalPointAI/SputnikDao-AS-Contract/tree/main/sputnikdao-as-factory
VotingPort of NEAR core-contract as AssemblyScripthttps://github.com/theophoric/near-core-contracts-as/tree/master/contracts/voting

必看的3个合约:

  • SputnikDAO
    这个合约是一个简单的DAO版本,用来分发小费、奖金和奖励。允许任何人发送一个提议,用资金奖励其他人,并得到理事会投票。这个和 Moloch DAO 设计的主要区别是这个合约将通过捐赠得到它的功能,并且理事会有平等的权利。

  • Multisig
    This contract provides a multisig scheme that allows making transfers, calling functions and adding / removing keys
    这个合约提供了一个multisig方案,允许进行传输、调用函数和添加/删除密钥

  • Whitelist
    The purpose of this contract is to maintain the whitelist of the staking pool contracts account IDs that are approved by NEAR Foundation.
    该合约的目的是维护由NEAR Foundation批准的权益池合约帐户ID的白名单。

SputnikDAO

https://github.com/VitalPointAI/SputnikDao-AS-Contract/tree/main/sputnikdao-as

github: https://github.com/VitalPointAI/SputnikDao-AS-Contract/tree/main/sputnikdao-as

SputnikDAO 帮助你在 NEAR 创建链上基金,并参与去中心化自治组织。

A smart contract written in AssemblyScript for an app initialized with create-near-app.
用AssemblyScript编写的针对使用create-near-app初始化的应用程序的智能合约。

多签合约(Multisig-Contract)

https://github.com/VitalPointAI/Multisig-Contract
相关参考: https://vitalpoint.ai/course/multisig-contract/

多重签名合约的整个前提是它可以实现要求多个人或实体在执行请求之前确认请求/提议的逻辑。这称为从N个多重签名方案中设置K个,其中N是参与者的总数,K是在执行请求或提议之前必须达成一致的数目。

此多重签名合约允许已添加到其中的密钥的所有者请求签名传输,函数调用或添加/删除现有或其他密钥。

没有时间限制。任何授权的访问密钥都可以进行确认,直至达到所需的确认数量。

让我们看一下整个过程的概述:
在这里插入图片描述
步骤1:初始化

  • 确定在执行某些请求操作之前我们需要多少确认;和
  • 我们要用来初始化的所有帐户的公钥(应该大于我们想要的确认数)。

例如,我要部署一个包含三个参与者(三个访问密钥)的多重签名,并且在执行任何操作之前,我想要两个单独的确认。换句话说,使用合同的三个人中的两个必须同意请求。

有了这些信息,我们可以部署调用它的initContract函数的合约。

当然,一个人可以分配任意数量的密钥,并增加或减少所需的确认数。一个人也可以稍后添加更多密钥或更改所需的确认数。

步骤2:FunctionCall存取键

NEAR具有两种访问键-fullAccess和functionCall访问。初始化时,我们设置了三个functionCall访问键,并赋予它们对methodNames数组标识的方法(“ add_request”,“ delete_request”和“ confirm”)的访问权限。因为它们是functionCall访问键-它们只能调用合约上的这三个更改功能(以及任何视图功能)。在上面的示例中,这三个键代表使用合约的三个人-A,B,C。

步骤3:提交请求

在星号3-用户C向合约提交多重签名请求。我们假设这是将资金转给某人的请求。附近。使用Near-CLI会采用以下形式:

转账要求

near call multisig.vitalpoint.ai add_request '{"request": {"receiver_id": "somebody.near", "actions": [{"type": "Transfer"}],  "amount": "1000000000000000000000" }}' --accountId multisig.vitalpointai.testnet

向Multisig添加另一个密钥

near call multisig.vitalpoint.ai add_request '{"request": {"receiver_id": "multisig.vitalpointai.testnet", "actions": [{"type": "AddKey"}],  "public_key": "<base58 of the key>"}}' --accountId multisig.vitalpointai.testnet

更改批准多重签名请求所需的确认数

near call multisig.vitalpoint.ai add_request '{"request": {"receiver_id": "multisig.vitalpointai.testnet", "actions": [{"type": "SetNumConfirmations"}],  "num_confirmations": 2}}' --accountId multisig.vitalpointai.testnet

所有这些都返回request_id,可用于查询/确认详细信息。还请记住,您可以创建将多个操作链接在一起的更复杂的调用。

请注意,合约“ add_request_and_confirm”中有一种方法与“ add_request”具有相同的功能,但是它通过添加请求的键将请求提交与确认结合在一起。如果使用“ add_request”提交,则用户(在这种情况下为C)仍然需要确认。不要忘记在初始化时将’add_request_and_confirm’添加到methodNames数组中,以提供适当的权限来调用它到访问键。

合约也有许多视图请求,您可以调用这些视图请求以获取一些信息:
列出所有请求ID

near view multisig.vitalpointai.testnet list_request_ids

查看有关特定请求的信息

near view multisig.vitalpointai.testnet list_request_ids

查看特定请求的确认

near view multisig.vitalpointai.testnet get_request '{"request_id: 0"}'

任何request 所需的确认总数

near view multisig.vitalpointai.testnet get_confirmations '{"request_id: 0"}'

步骤4:确认
在星标4处-用户的B和C都在合约上调用“确认”方法,以表明他们对关联的request_id的支持。非常简单。看起来像这样:

near call multisig.vitalpointai.testnet confirm '{"request_id": 0}' --accountId multisig.vitalpointai.testnet

当我们初始化需要2/3确认的合约时-用B&C的确认,它会触发execute_request函数,该函数将我们带到最后一步。

步骤5:执行
执行正是听起来的样子。由于在步骤3提交的请求收到了必要的两次确认,因此execute_request函数将执行并执行属于请求的任何动作(假定所有相关参数都存在)。他们包括:

  • 转移
  • 创建帐号
  • 部署帐户
  • AddKey
  • 删除键
  • 函数调用
  • SetNumConfirmations
MultiSig合约有什么好处呢?

发挥您的想象力-可能会想到许多情况,在这种情况下,提交请求并在参与人员中达成多数(或其他共识)是有意义的。

从本质上讲,这就是去中心化自治组织(DAO)的运行方式,在这种情况下,NEAR的帐户和访问密钥系统以及multisig合约为实现这些系统开辟了一些新颖的方式。

这种多重信号可能是超级健壮的DAO的开始。可以将合约扩展为包括其他各种请求类型,并且DAO的成员(如其访问键所示)可以指示对某些请求的支持,添加/删除其他成员或您能想到的任何其他内容。

它是可升级的
但如果您决定这样做,请务必小心-以下请求将在给定帐户上部署新的合同代码。您需要考虑数据并需要迁移(合同更新应包括向前迁移的数据)。


const fs = require('fs');
const account = await near.account("vitalpointai.testnet");
const contractName = "multisig.vitalpointai.testnet";
const requestArgs = {"request": [
     {"receiver_id": "multisig.illia", "actions": [{"type": "DeployContract", "code":       

     fs.readFileSync("out/multisig.wasm")}]}
]};
const result = account.signAndSendTransaction(
     contractName,
     [
     nearAPI.transactions.functionCall("add_request", Buffer.from(JSON.stringify(requestArgs)),

     10000000000000, "0"),
]);

这仍然像是一个请求,并且需要通过合约的确认数量来进行确认。

Whitelist

https://github.com/VitalPointAI/Whitelist-Contract

The purpose of this contract is to maintain the whitelist of the staking pool contracts account IDs that are approved by NEAR Foundation.

该合约的目的是维护由NEAR Foundation批准的权益池合约帐户ID的白名单。

Counter

https://github.com/near-examples/counter

该合约实现了由存储在区块链上支持的简单计数器。

深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值