首先,让我提一下这是一个浏览器内项目,所以我只能使用
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
几个月前,我制作了一个 dapp,即使我从未设置过提供程序,它也能正常工作,所以我猜它使用了 MetaMask 提供的提供程序。但是,我在这里使用指南,唯一的问题是以下代码,
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
此代码用于在元掩码用户在我的 dapp 上批准元掩码后输出元掩码用户的地址,但是我收到了错误
Uncaught (in promise) TypeError: Cannot read property 'request' of undefined
Run Code Online (Sandbox Code Playgroud)
该错误只是说,如果我必须添加提供程序,我的实际目标是使用元掩码中的提供程序,并允许连接到元掩码,其余功能(例如传输或其他我知道如何处理它们),它只是当我尝试加载页面时,似乎我的问题出现了。
我没有可用的以太节点,也不打算使用nodejs,只有一个显示Metamask地址的html文件,因此使用浏览器内的web3js。
我希望这只是我没有意识到一些简单的事情,因为我似乎找不到现在不能使用 web3js 的原因。
我正在构建一个分散的应用程序,用户可以在其中将他们的加密货币钱包 (Metamask) 连接到我的网站。
They can initiate a connection request by clicking a button. On success, the wallet is connected and my website can interact with it.
Is there any way to initiate a disconnect request? Similar to a 'Log out' button. Currently, the users have to manually disconnect their wallet within Metamask settings which is not a straightforward process.
我一直在运行一个本地的Rinkeby节点(为了使用websocket事件),这个节点工作正常一段时间,但突然间我得到了"返回错误:替换事务价格过低".我发送的平均汽油价格是10倍,我仍然收到这个错误.这是我的计算:
gwei = 1000000000
gas = 47000
gasPrice = gwei * 20
Run Code Online (Sandbox Code Playgroud)
只有当我将汽油价格提高到(gwei*2000)时才能进行交易(0.9以太).这导致我很快耗尽以太,使开发变得非常困难.
示例tx:
{
"nonce": "0x23",
"chainId": 4,
"to": "0xB92427792629A23E0b2deE37b3F92Ce4D4cB794c",
"value": 0,
"gas": "0xb798",
"gasPrice": "0x4a817c800",
"data": "0xce07c1787465737400000000000000000000000000000000000000000000000000000000"
}
Run Code Online (Sandbox Code Playgroud)
任何帮助都很受欢迎!
Geth Rinkeby Cmd:
geth --rpccorsdomain="*" --rinkeby --ws --wsport=8546 --wsorigins="*" --datadir=$HOME/.rinkeby --cache=512 --rpc --rpcapi="personal,eth,network,net,web3,db" --rpcport=8545 --fast --bootnodes=enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@52.169.42.101:30303
Run Code Online (Sandbox Code Playgroud) 我想从账户A在以太坊进行交易,但交易费用应该从账户B支付。在以太坊可以吗?
我正在尝试使用 ethers.js 创建一条链下签名消息,并使用 验证该消息在链上ecrecover。我正在从我的元掩码钱包签署正确的消息,并将该签名中的 r、s 和 v 传递到 ecrecover,但没有与我的元掩码钱包匹配。
我的可靠性代码应该适用于带前缀或不带前缀的签名。
这是我用来验证签名的合同:
pragma solidity ^0.5.0;
contract SignatureVerifier {
/// @dev Signature verifier
function isSigned(address _address, bytes32 messageHash, uint8 v, bytes32 r, bytes32 s) public pure returns (bool) {
return _isSigned(_address, messageHash, v, r, s) || _isSignedPrefixed(_address, messageHash, v, r, s);
}
/// @dev Checks unprefixed signatures.
function _isSigned(address _address, bytes32 messageHash, uint8 v, bytes32 r, bytes32 s)
internal pure returns (bool)
{
return ecrecover(messageHash, v, r, s) == _address; …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Web3 添加到 React 项目。\n我已经使用以下命令初始化了一个新项目
\ngatsby new\nRun Code Online (Sandbox Code Playgroud)\n然后,我安装了web3
\nnpm install --save web3\nRun Code Online (Sandbox Code Playgroud)\n当我在 index.js 中包含 web3 时
\nimport Web3 from 'web3'\nRun Code Online (Sandbox Code Playgroud)\n如果我打电话
\ngatsby develop\nRun Code Online (Sandbox Code Playgroud)\n我有一些奇怪的错误:
\n\n\n./node_modules/eth-lib/lib/bytes.js 9:193-227\n中出现错误:找不到模块:错误:无法解析“/home/test/gatsby/test/test/node_modules/eth”中的“加密” -lib/lib'
\n
\n\n重大更改:webpack < 5 过去默认包含 Node.js 核心模块的 Polyfill。\n现在情况已不再如此。验证您是否需要此模块并为其配置一个polyfill。
\n
\n如果你想包含一个polyfill,你需要:\n- 添加后备 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'\n- 安装 'crypto-browserify'\如果你不想包含一个polyfill,你可以使用一个空模块,如下所示:\nresolve.fallback: { "crypto": false }\n\xc2\xa0@ ./node_modules/swarm-js/lib/api -browser.js 32:12-40\n\xc2\xa0@ ./node_modules/web3-bzz/lib/index.js 24:12-31\n\xc2\xa0@ ./node_modules/web3/lib/index .js 34:10-29\n\xc2\xa0@ ./src/pages/index.js 9:0-24\n\xc2\xa0@ ./.cache/ this_is_virtual_fs_path /$virtual/async-requires.js 21:11-23:5\n\xc2\xa0@ ./.cache/app.js 17:0-52 …
我在我的网站(Laravel 和 Vuejs)上使用元掩码登录。我安装了 Web3 并执行 getAccounts、Sign 、 getBalance 等操作。
但我想获取metamask中的所有代币(如BNB、RARI等)余额。我写了这段代码:
// accounts[0] => default wallet number
window.web3.eth.getBalance(accounts[0], (err, b) => {
if (err)
console.log(err);
let balance = {};
balance.ether = window.web3.utils.fromWei(b, "ether");
});
Run Code Online (Sandbox Code Playgroud)
但只返回 ETH 代币余额而不是所有代币。
我如何获得所有代币余额?你能帮助我吗?
我是区块链新手。
我做了一些研究,以下是我使用 web3.js 获取某个钱包拥有的 NFT 列表的步骤
balance = ERC721.methods.balanceOf(walletAddress).call();
objects = [];
for (i = 0; i < balance; i++) {
tokens.push(await ERC721.methods.tokenOfOwnerByIndex(walletAddress, i).call());
}
for(i = 0; i < tokens.length; i++){
objects.push(await ERC721.methods.tokenURI(tokenIdList[i]).call());
}
Run Code Online (Sandbox Code Playgroud)
我可以使用上述方法获取 ERC721 令牌 URI 列表,但性能非常差。我想知道 OpenSeas 如何在相同功能上以光速性能实现这一目标。
我实现了一个短代码,它连接到metamask浏览器扩展并使用web3 和reactjs显示用户帐户,该代码在使用桌面浏览器时效果很好,但是当我在移动浏览器上尝试时,metamask移动版本由于非-其扩展程序在移动浏览器中的存在,像opensea这样的网络应用程序如何使用移动网络浏览器上的按钮打开metamask移动应用程序?
代码 :
export const connectWallet = async () => {
if (window.ethereum) {
try {
const addressArray = await window.ethereum.request({
method: "eth_requestAccounts",
});
const obj = {
status: " Write a message in the text-field above.",
address: addressArray[0],
};
return obj;
} catch (err) {
return {
address: "",
status: "... " + err.message,
};
}
} else {
return {
address: "",
status: (
<span>
<p>
{" "}
{" "}
<a …Run Code Online (Sandbox Code Playgroud) 我正在尝试验证从用户那里获得的输入文本是否是有效的 Solana 地址。
根据 web3.js 文档,方法 .isOnCurve() 执行以下操作:
https://solana-labs.github.io/solana-web3.js/classes/PublicKey.html#isOnCurve
我已经设法让它与这段代码一起工作:
import {PublicKey} from '@solana/web3.js'
function validateSolAddress(address:string){
try {
let pubkey = new PublicKey(address)
let isSolana = PublicKey.isOnCurve(pubkey.toBuffer())
return isSolana
} catch (error) {
return false
}
}
function modalSubmit(modal: any){
const firstResponse = modal.getTextInputValue(walletQuestFields.modal.componentsList[0].id)
let isSolAddress = validateSolAddress(firstResponse)
if (isSolAddress) {
console.log('The address is valid')
}else{
console.log('The address is NOT valid')
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我传递 let pubkey = new PublicKey(address)一个与 solana 地址不相似的字符串时,它会抛出异常Error: Invalid public key input (PublikKey 需要一个 PublicKeyInitData: …
web3js ×10
ethereum ×5
javascript ×4
metamask ×4
blockchain ×2
reactjs ×2
browser ×1
ethers.js ×1
geth ×1
node.js ×1
solana ×1
solidity ×1
typescript ×1