什么是Brownie?
使用Python部署您的第一个智能合约
1.安装Brownie
pip install eth-brownie
npm install -g ganache-cli
brownie bake chainlink-mix
cd chainlink
:
build :这是项目跟踪已部署的智能合约和已编译合约的地方
contracts:合同的源代码,通常以solidity或vyper
interfaces:处理已部署合同所需的接口布局。每次与合同的交互都需要一个ABI和一个地址。接口是获取合同的ABI的好方法
scripts :我们创建的脚本可自动执行合同工作
tests :测试
brownie-config.yaml:这是我们拥有布朗尼所有信息的地方,以了解如何使用我们的智能合约。我们想部署到什么区块链?我们是否需要设置任何特殊参数?所有这些都在配置文件中设置。
2.设置环境变量
3.部署您的智能合约
brownie run scripts/price_feed_scripts/deploy_price_consumer_v3.py --network kovan
Running 'scripts/price_feed_scripts/deploy_price_consumer_v3.py::main'...
Transaction sent: 0x23d1dfa3937e0cfbab58f8d5ecabe2bfffc28bbe2349527dabe9289e747bac56
Gas price: 20.0 gwei Gas limit: 145600 Nonce: 1339
PriceFeed.constructor confirmed - Block: 22721813 Gas used: 132364 (90.91%)
PriceFeed deployed at: 0x6B2305935DbC77662811ff817cF3Aa54fc585816
4.阅读您的智能合约
brownie run scripts/price_feed_scripts/read_price_feed.py --network kovan
Brownie v1.12.2 - Python development framework for Ethereum
ChainlinkProject is the active project.
Running 'scripts/price_feed_scripts/read_price_feed.py::main'...
Reading data from 0x6B2305935DbC77662811ff817cF3Aa54fc585816
62322000000
5.使用web3.py
pip install web3
web3 = Web3(Web3.HTTPProvider('https://kovan.infura.io/v3/<infura_project_id>'))
abi = '[{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"description","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"_roundId","type":"uint80"}],"name":"getRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]'
addr = '0x9326BFA02ADD2366b30bacB125260Af641031331'
contract = web3.eth.contract(address=addr, abi=abi)
latestData = contract.functions.latestRoundData().call() print(latestData)
作者:链三丰,来源:区块链研究实验室
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。