我需要像这样转换以太坊地址
0xB34080739D5B656D76089f9f21b374BA5dafA373
像这样的公钥
e2d3a3a43e71eb541e12504cee22ed74024969b46b9e68ea7f9e5384fe96fc04
我是这样得到地址的
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://sokol.poa.network'))
addr = w3.toHex(w3.sha3(text=public_key)[12:])
Run Code Online (Sandbox Code Playgroud)
也许有一个图书馆可以做到这一点?请帮忙
我们可以将资金从地址(此)转移到收件人。但是有没有什么方法可以将资金直接从 msg.sender 钱包转移到收件人呢?我无法在调用 payoutBonus 调用时设置 msg.value。因为我只能在 payoutBonus 方法中获得金额。
function payoutBonus(address recipient) public payable returns (bool) {
// bonus = calculateBonus();
//transfer this bonus to recipient from msg.sender;
return true;
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个带有 webpack 的小型 Dapp 和基于 Web 组件(lit-library)的 UI。为了捆绑文件,我使用 webpack 和 webpack-dev-server 来刷新页面。一切对我来说都很好。
现在,我尝试使用 web3 与我的智能合约交互,但是当我导入 web3 并从中创建一个新实例时,出现以下错误:
Uncaught Error: Cannot find module 'http'
webpackMissingModule xml-http-request.js:21
js xml-http-request.js:21
Webpack 14
xml-http-request.js:21:19
webpackMissingModule xml-http-request.js:21
js xml-http-request.js:21
Webpack 14
__webpack_require__
js
__webpack_require__
js
__webpack_require__
js
__webpack_require__
js
__webpack_require__
js
__webpack_require__
<anonymous>
<anonymous>
<anonymous>
Run Code Online (Sandbox Code Playgroud)
此错误出现在我的 Firefox 的控制台中。
Uncaught Error: Cannot find module 'http'
webpackMissingModule xml-http-request.js:21
js xml-http-request.js:21
Webpack 14
xml-http-request.js:21:19
webpackMissingModule xml-http-request.js:21
js xml-http-request.js:21
Webpack 14
__webpack_require__
js
__webpack_require__
js
__webpack_require__
js
__webpack_require__ …Run Code Online (Sandbox Code Playgroud) 我正在用 React 构建一个简单的应用程序,但是var manager = wait lottery.methods.manager().call(); 永远不会检索值,我怎么会错呢?
彩票.js
import web3 from './web3';
const address = '0x430b45dcf781d58e73CeeA288b4196B6ddeE4d7E';
const abi = [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"enter","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getPlayers","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pickWinner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"players","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"random","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}];
const cont = new web3.eth.Contract(abi,address);
export default cont;
Run Code Online (Sandbox Code Playgroud)
应用程序.js
import React,{Component} from 'react';
import logo from './logo.svg';
import './App.css';
import web3 from './web3';
import lottery from './lottery';
class App extends Component {
constructor (props){
super(props);
this.state = {"manager":''};
}
async componentDidMount(){
console.log("componentDidMount fired");
var manager = await lottery.methods.manager().call();//never set manager var
this.setState({manager});
}
render() {
return (
<div> …Run Code Online (Sandbox Code Playgroud) 我在 Ropsten 以太坊测试网络上部署了以下智能合约,之后我尝试使用 @alch/alchemy-web3 npm 包进行交易(是的,我正在使用 Alchemy API),但正如你所看到的,我在交易中收取了费用。这是为什么?公共视图函数调用不应该花费 0 Gas 吗?
\n部署的智能合约
\n// SPDX-Lincense-Identifier: MIT\npragma solidity ^0.8.11;\n\ncontract VendingMachine {\n address public owner;\n mapping(address => uint256) public donutBalances;\n\n constructor() {\n owner = msg.sender;\n donutBalances[address(this)] = 100;\n }\n\n function getVendingMachineBalance() public view returns (uint256) {\n return donutBalances[address(this)];\n }\n\n function restock(uint amount) public {\n require(msg.sender == owner, "Only the owner can restock this machine.");\n donutBalances[address(this)] += amount;\n }\n\n function purchase(uint amount) public payable {\n require(msg.sender == owner, "Only the owner can …Run Code Online (Sandbox Code Playgroud) 如何覆盖 Opezeppelin 默认小数点 18。文档说 _setupDecimals() 应该从构造函数调用;我究竟做错了什么。
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
uint8 _decimals;
constructor() ERC20("MyToken", "MTK") {
_decimals = 3;
function _setupDecimals(uint8 decimals_) internal {
_decimals = decimals_;
}
_mint(msg.sender, 5000 * 10 ** decimals());
}
}
Run Code Online (Sandbox Code Playgroud) 我在将 web3 导入到 ReactJS 时遇到问题。要复制我的问题,请初始化一个新的反应应用程序
npx create-react-app my-app
cd my-app
Run Code Online (Sandbox Code Playgroud)
然后在此位置打开终端。写:
npm install web3
npm install
Run Code Online (Sandbox Code Playgroud)
在 App,js 文件中添加以下行
import Web3 from "web3";
Run Code Online (Sandbox Code Playgroud)
我在执行此操作后收到错误,npm start然后收到未解决的错误,即
找不到模块:错误:无法解析“流”
找不到模块:错误:无法解析“加密”
我尝试在网上寻找解决方案,特别是我尝试了以下每个
似乎没有人适合我。对于如何解决这个问题有什么建议吗?谢谢你!
我有网络应用程序,企业应用程序的背景.有了这样的背景; 我在哪里适合区块链!什么是最简单的术语!
ethereum ×9
solidity ×4
javascript ×2
reactjs ×2
web3js ×2
blockchain ×1
public-key ×1
python ×1
typescript ×1
web3-react ×1
webpack ×1