web3.py概述

基于Kovan测试网学习Web3.py 环境部署: RPC查询:RPC Info 基于测试网Ropsten学习Web3.py 官方文档:Introduction — Web3.py 5.28.0 documentation from web3 import Web3,HTTPProvider address = "0xBA56BE272416d6C2385F8e183D2647AFdE7Cf6eF" ropsten_network_rpc = "https://ropsten.infura.io/v3/9aa3d95b3bc440fa 阅读详情

与web3.py库交互的共同入口是web3对象。web3对象提供API,用于python开发的应用与以太坊区块链进行交互,通常是通过连接JSON-RPC服务器进行。

Providers提供者

Providers使web3连接到区块链上。Web3.py库带有以下内置的providers,它们能够适用于大多数用例。

  • web3.HTTPProvider:用于连接基于http和https的JSON-RPC服务器。
  • web3.IPCProvider:用于连接基于ipc套接字的JSON-RPC服务器。
  • web3.WebsocketProvider:用于连接基于ws和wss的websocket的JSON-RPC服务器。

HTTPProvider:用于获取可以找到服务器的完整URI。对于本地开发,这类似http://localhost:8545。

IPCProvider:用于获取可以找到IPC套接字的文件系统路径。如果不提供任何参数,它将使用操作系统的默认路径。

WebsocketProvider:用于获取可以找到服务器的完整URI。对于本地开发,这类似ws://127.0.0.1:8546。

示例代码如下:

>>> from web3 import Web3, HTTPProvider, IPCProvider, WebsocketProvider

# Note that you should create only one RPCProvider per
# process, as it recycles underlying TCP/IP network connections between
# your process and Ethereum node
>>> web3 = Web3(HTTPProvider('http://localhost:8545'))

# or for an IPC based connection
>>> web3 = Web3(IPCProvider())

# or for Websocket based connection
>>> web3 = Web3(WebsocketProvider('ws://127.0.0.1:8546'))

基本API

web3类提供了以下十分便利的基本API:

类型转换

web3.toHex

Web3.toHex(primitive=None, hexstr=None, text=None)

获取各种输入并以十六进制表示形式返回它。它遵循在JSON-RPC规范中转换为十六进制的规则。

>>> Web3.toHex(0)
'0x0'
>>> Web3.toHex(1)
'0x1'
>>> Web3.toHex(0x0)
'0x0'
>>> Web3.toHex(0x000F)
'0xf'
>>> Web3.toHex(b'')
'0x'
>>> Web3.toHex(<
以太坊数据开发-Web3.py-安装连接以太坊数据 Web3.py是连接以太坊的python库,它的API从web3.js中派生而来。如果你用过web3.js,你会对它的API很熟悉。但惭愧的是,作为一个以太坊上Dapp的开发者,我几乎没有直接使用过web3.js,也没有看过它的API。 阅读详情

相关推荐

使用Web3.py构建、签署、发送以太坊交易

无论是普通转账,还是智能合约的写入,都可以认为是一笔交易(Transaction)。在区块链世界,可导致区块链数据发生变化的数据,可简单理解为一笔“交易”。相反,send_raw_transaction处理的,反而是对以上文本数据进行签署后,生成的数据(二进制或16进制形式)。B. 构建build_transaction() + 签署sign_transaction + 发送send_raw_transaction()A. 使用transact(), 底层还是自动调用的send_transaction()

Iwerehappy的博客 1460

使用Web3.py连接Ethereum

毕业设计做了相关区块链的项目,在考虑了Hyperledger和Ethereum之后选择使用了Ethereum,因为在Ethereum上用智能合约,代币等更方便。然而对于Ethereum,国内对于Python来开发的教程还不够多,我就想把毕设中踩得坑记录下来。 本文提供的代码上传至https://github.com/crazylnx/bupt-homework/tree/master/%E6%...

m0_37557541的博客 1671

通过 web3.py 用 Python 存取 Ethereum

想要通过 Python 存取 Ethereum,从 Ethereum 官方的 Github 中可以看到有两种模块可以达成:web3.py 和 pyethereum。就我目前的理解来说,两者的差别在于 web3.py 主要是作为外部存取 Ethereum 的客户端,也就是说 web3.py 函数库本身不会成为区块链节点,也不会进行区块链同步,而是连接一个区块链上的节点,把区块链当成是外部资料库一样取用而已;

Saki_Python的博客 561

web3.py的几种连接以太坊节点的方法

通信服务提供接口是web3如何与区块链交互的关键。接口接受JSON-RPC请求并返回响应。这通常通过将请求提交给基于HTTP或IPC套接字的服务器来完成。 如果你已经愉快地连接到你的以太坊节点,那么你可以跳过这部分内容。 选择如何连接到你的节点 大多数节点都有多种连接方式。如果你尚未确定要使用哪种节点,请转到如何选择要使用的节点? 连接节点的最常用方法是: 1.IPC(使用本地文件系统:最快,最...

mongo_node的专栏 4872

web.py中文版用户手册

web.py 是一个轻量级Python web框架,它简单而且功能强大。web.py是一个开源项目。该框架由美国作家、Reddit联合创始人、RSS规格合作创造者、著名计算机黑客Aaron Swartz开发。web.py目前已被很多家大型网站所使用。

从零构建:基于Docker与FRR的OSPF虚拟网络实验室

本文详细介绍了如何利用Docker与FRR构建OSPF虚拟网络实验室,从环境设计到高级网络拓扑配置,再到实验验证与排错。通过容器化技术实现高效资源利用和快速部署,特别适合网络协议教学、企业网络架构验证等场景。

plum99的博客 235

Windows Server+SqlServer Always On实战:5步搞定高可用集群搭建

本文详细介绍了在Windows Server环境中,通过5个关键步骤搭建SQL Server Always On高可用集群的实战指南。内容涵盖从底层故障转移集群配置、SQL Server实例启用Always On功能,到创建可用性组和侦听器的完整流程,并提供了核心运维与故障排查思路,帮助企业构建稳定可靠的数据库高可用架构。

milk5的博客 879

3D缺陷检测实战:从点云处理到工业质检优化

本文深入探讨了3D缺陷检测在工业质检中的实战应用,详细阐述了从点云处理到深度学习模型部署的完整技术链路。文章通过PCB焊点检测等实际案例,分析了3D视觉相比2D检测在识别深度、形状等缺陷方面的优势,并分享了点云滤波、分割、特征提取以及利用YOLOv5等模型进行高效检测的优化心得与落地挑战。

weixin_28358083的博客 345

MATLAB 设置legend加标题

x1 = linspace(0,5); y1 = sin(x1/2); plot(x1,y1) hold on x2 = [0 1 2 3 4 5]; y2 = [0.2 0.3 0.6 1 0.7 0.6]; scatter(x2,y2,'filled') hold off legend({'sin(x/2)','2016'},'Location','northwest','Orientation','horizontal')%水平 legend添加标题 lgd = legend; lgd.Fon

早起CaiCai的学习空间 4730

ROS2机械臂控制实战:从MoveIt2规划到Panda真机迁移

机器人操作系统(ROS2)已成为机器人开发的主流框架,它将复杂的机器人控制任务拆解为模块化组件。在机械臂控制领域,运动规划与执行控制是两个核心层次:MoveIt2负责感知环境和规划无碰撞轨迹,而ROS2 Control则负责将轨迹转化为实际关节指令。理解两者的协作关系,是搭建机器人控制系统的关键。该架构通过硬件接口抽象层,实现了仿真与真机的平滑迁移。在Gazebo仿真环境中,开发者可以安全地验证规划算法、控制器参数与避障逻辑,再利用统一的ROS2 Control接口切换到真实机械臂。基于Panda机械臂的完

weixin_28683165的博客 256

Windows/Linux双平台实战:QtCreator构建套件配置全攻略(含GCC/G++/GDB/CMake)

本文详细介绍了在Windows和Linux双平台下配置QtCreator构建套件的完整流程,涵盖GCC/G++、GDB和CMake等核心工具链的设置技巧。通过分步指导和实用示例,帮助开发者解决跨平台开发中的配置难题,提升Qt应用开发效率。特别针对QtCreator新手和需要在多平台切换的开发者提供了全面的配置指南。

weixin_28836507的博客 478

100天精通Python(进阶篇)——第43天:批量将PDF转Word文档(附上脚本代码)

100天精通Python(进阶篇)——第43天:批量将PDF转Word文档(附上脚本代码)

努力让自己发光,对的人才能迎着光而来 9万+

Python爬虫实战:高效爬取中国专利数据库的完整指南

在当今信息爆炸的时代,专利数据作为技术创新的重要指标,对企业研发、市场分析和学术研究都具有极高价值。中国作为全球专利申请量最大的国家,其专利数据库包含了海量的技术创新信息。本文将详细介绍如何使用Python最新技术构建一个高效、稳定的中国专利数据库爬虫系统。中国专利数据库主要由国家知识产权局(CNIPA)维护,包含发明专利、实用新型专利和外观设计专利三大类。截至2023年,中国专利数据库已收录超过400万件发明专利和300万件实用新型专利。

2201_76125261的博客 1585

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

上一篇: web3j获得的sha3值和solidity为什么会不同?
下一篇: Android中使用web3j时出现内存溢出错误:OutOfMemoryError
落叶无声9
博客等级 码龄12年 443粉丝 343原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址