我\xe2\x80\x99m 尝试创建一个包含 10 个整数的数组 ( uint256) 并对其初始起始值进行硬编码 - 但我不断收到以下错误(奇怪地谈论uint16,即使我特别要求uint256):
TypeError: Type uint16[10] memory is not implicitly convertible to expected type uint256[] memory.\nRun Code Online (Sandbox Code Playgroud)\n这里\xe2\x80\x99是我的代码:
\nuint256 memory myNumbersArray = new uint256[](10);\nmyNumbersArray = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]; \nRun Code Online (Sandbox Code Playgroud)\n我也尝试过这样的方法:
\nuint256[10] memory myNumbersArray;\nmyNumbersArray = [0, 100, 200, 300, 400, 500, 600, 700, 800, 900]; \nRun Code Online (Sandbox Code Playgroud)\n结果相同。
\n(我想我也尝试过用一行来完成整个事情。)
\n我收到此错误是因为 I\xe2\x80\x99m 分配的实际值太小,以至于它们不需要\xe2\x80\x99t 类型吗uint256?
\n我需要知道这一点,因为该数组应该保存的未来 …
我对 MetaMask 中的交易有一个关于值格式的问题,我将代码放在下面:
<script type="text/javascript">
const sendEthButton = document.querySelector('.sendEthButton');
sendEthButton.addEventListener('click', () => {
ethereum
.request({
method: 'eth_sendTransaction',
params: [
{
from: ethereum.selectedAddress,
to: '{{contractCreator}}',
value: '0x29a2241af62c0000',
},
],
})
.then((txHash) => console.log(txHash))
.catch((error) => console.error);
});
</script>
Run Code Online (Sandbox Code Playgroud)
我已将 MetaMask 正确连接到网站和 Ganache,当我按下页面中的按钮时,交易也会出现在插件中,但只有在代码中使用此值时,我才能看到正确的值 (3),但我不知道如何是格式化。
我尝试过 web3.toWei(number, 'ether') 和 web3.toHex(number) 但它显示了奇怪的值。
例如,如果我用 web3.toWei(1, ether) 替换该值,它会在 MetaMask 窗口中显示 4722.366483。
我正在运行一个使用truffle initCMD 命令创建的 truffle 项目。npx reate-react-app然后我在同一文件夹中创建一个反应应用程序。我正在创建一个 NFT,因此我使用npm install @openzeppelin/contracts命令在我的 React 应用程序中安装了 OZ 合约。
现在整个项目看起来像这样。
根文件夹
包.json
这是完整的truffle-config.js
/**
* Use this file to configure your truffle project. It's seeded with some
* common settings for different networks and features like migrations,
* compilation and testing. Uncomment the ones you need or modify
* them to suit your project as necessary.
*
* More information about configuration can be found at:
*
* trufflesuite.com/docs/advanced/configuration …Run Code Online (Sandbox Code Playgroud) 我通过在 ERC20.sol 文件中实现 OpenZeppelin 创建了一个基本的 ERC20 令牌,如下所示:
pragma solidity ^0.6.4;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.0/contracts/token/ERC20/ERC20.sol";
contract Token is ERC20 {
constructor(string memory _name, string memory _symbol)
public
ERC20(_name, _symbol)
{
_mint(msg.sender, 10000000000000000000000000000);
}
}
Run Code Online (Sandbox Code Playgroud)
然后实现另一个合约Contract.sol,如下:
import "./ERC20.sol";
pragma solidity ^0.6.4;
contract SimpleBank{
Token tokenContract;
constructor(Token _tokenContract) public {
tokenContract = _tokenContract;
}
function deposit(uint amt) public returns (bool) {
require(amt != 0 , "deposit amount cannot be zero");
tokenContract.transfer(address(this),amt);
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
因为,我已经从地址0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2部署了两个合约,所以它持有 10000000000000000000000000000 个代币。
但是当我deposit从同一地址调用函数时,出现以下错误:
交易到 SimpleBank.deposit …
下面的代码是一个流行的Solidity以太坊函数
function: swapExactETHForTokens(uint256 amountOutMin, address[] path, address to, uint256 deadline)
Run Code Online (Sandbox Code Playgroud)
Go 中的类型应该amountOutMin是什么样的?
这是我在 Go 中尝试过的:
function: swapExactETHForTokens(uint256 amountOutMin, address[] path, address to, uint256 deadline)
Run Code Online (Sandbox Code Playgroud)
错误信息:
不能使用 int 作为 ptr 类型作为参数
显示amountOutMin是一个指针,而solidity的声明是uint256。很混乱
编辑:
最小可重复示例
amountOutMin := 20
data, err := routerABI.Pack("swapExactETHForTokens", amountOutMin, path, to, deadline)
Run Code Online (Sandbox Code Playgroud)
运行上面的代码
package main
import (
"fmt"
"log"
"strings"
"time"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
)
const (
WETH = "0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6"
tokenWanted = "0x2aC3c1d3e24b45c6C310534Bc2Dd84B5ed576335"
)
func main() {
now := time.Now()
deadline := now.Add(10*time.Minute).Unix()
tokenWantedAddress …Run Code Online (Sandbox Code Playgroud) 我正在运行以下函数
import { ethers } from "ethers";
async function requestAccount() {
await window.ethereum.request({ method: "eth_requestAccounts" });
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是我正在使用打字稿,它抱怨以下错误
Property 'ethereum' does not exist on type 'Window & typeof globalThis'
所以我能够用以下方法修复它
declare global {
interface Window{
ethereum?:any
}
}
Run Code Online (Sandbox Code Playgroud)
但是我认为这没有正确利用打字稿。我该如何编写才能使接口值正确。我认为它应该是一个内部有方法的对象,但不确定如何在打字稿中编写它。
任何帮助将不胜感激。
谢谢
是否可以在没有源代码的情况下获取已知合约地址的ABI?
我发现的唯一方法是使用 etherscan 的 API,但它仅适用于经过验证的合约。
我正在使用 web3.js 库开发一个小项目,该项目订阅 NFT 智能合约上的事件,以通过 OpenSea 跟踪该项目的所有销售。当使用 ETH 完成销售时,这种方法工作正常,但是当使用 OpenSea 提供的另一种付款方式(USDC、DAI、WETH 等)进行销售时,来自 web3.js 的交易价值将返回为 0 ,并且在 etherscan.io 上也显示 0。以下是代表此问题的示例交易:https://etherscan.io/tx/0x17f050e3fb6d8f0bbb4d9b4e8cd477f8197a87a3a68b360a60a028d7b1037532。无论使用什么类型的货币,关于如何获得正确价值的任何想法?
前的
web3.eth.getTransaction('0x17f050e3fb6d8f0bbb4d9b4e8cd477f8197a87a3a68b360a60a028d7b1037532').then((response) => {
console.log(response);
Run Code Online (Sandbox Code Playgroud)
});
回复
{
accessList: [],
blockHash: '0x6140d3cb5c271fb351e0a6e9e35b32cf0607ad526152f40f2d98107a97b0212b',
blockNumber: 13545512,
chainId: '0x1',
from: '0x3F4D7b0Eba8CB40D94713023d9Dc02FdB0a5169C',
gas: 391246,
gasPrice: '157998874325',
hash: '0x17f050e3fb6d8f0bbb4d9b4e8cd477f8197a87a3a68b360a60a028d7b1037532',
input: '0xab834bab0000000000000000000000007be8076f4ea4a4ad08075c2508e481d6c946d12b00000000000000000000000074144fb8749f99382091118f7487f4a541be6d7700000000000000000000000000000000000000000000000000000000000000000000000000000000000000005b3256965e7c3cf26e11fcaf296dfc8807c01073000000000000000000000000bd3531da5cf5857e7cfaa92426877b022e612cf80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000007be8076f4ea4a4ad08075c2508e481d6c946d12b0000000000000000000000003f4d7b0eba8cb40d94713023d9dc02fdb0a5169c00000000000000000000000074144fb8749f99382091118f7487f4a541be6d770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000bd3531da5cf5857e7cfaa92426877b022e612cf80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000226000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000165a0bc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000618193b7000000000000000000000000000000000000000000000000000000006182e53b690c3f82a9b6570ef2de1af15e15942c931dba8a2bd9d5012b74b213beea4da400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000226000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000165a0bc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006182d5b70000000000000000000000000000000000000000000000000000000000000000065ae400a094fafb63173dcf4c7861ca0264920136639dbe27b5956aa6282bb00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006a0000000000000000000000000000000000000000000000000000000000000074000000000000000000000000000000000000000000000000000000000000007e0000000000000000000000000000000000000000000000000000000000000088000000000000000000000000000000000000000000000000000000000000009200000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000001c08da96edfaed45809c68db44cabb487dba56fd196fe46d02d679f0161dee94293eaedf214e043bc4d2e3dd69cce82e21ead967d7f1cd8fc505c04781e2d144e308da96edfaed45809c68db44cabb487dba56fd196fe46d02d679f0161dee94293eaedf214e043bc4d2e3dd69cce82e21ead967d7f1cd8fc505c04781e2d144e35c5321ae45550685308a405827575e3d6b4a84aa000000000000000000000000000000000000000000000000000000000000000000000000000000000000006423b872dd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000074144fb8749f99382091118f7487f4a541be6d7700000000000000000000000000000000000000000000000000000000000008ff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006423b872dd0000000000000000000000003f4d7b0eba8cb40d94713023d9dc02fdb0a5169c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008ff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006400000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
maxFeePerGas: '201893464202',
maxPriorityFeePerGas: '1500000000',
nonce: 19,
r: '0x4c8e6fbe4a49439d957e0e725f3f7e897329557a972863143ff2a34458ab190',
s: '0x25afd4caa4cdc1f93923b5f41a89bc191d0e52c27a36e51e3015ed08560fea5d',
to: '0x7Be8076f4EA4A4AD08075C2508e481d6C946D12b',
transactionIndex: 328,
type: 2,
v: '0x1',
value: '0'
}
Run Code Online (Sandbox Code Playgroud) 我需要检查一笔交易是否是 ERC721/ERC1155 交易,并获取接收地址、代币地址、价值等信息。如果我理解正确,我必须加载该交易的合约并检查它是否继承 ERC165,以便确认这是一笔ERC721/ERC1155交易。
问题:我不明白如何获得具有交易对象的合同。我还没有找到获取令牌地址的方法。
我在 Infura 上有一个以太坊节点,我从那里读取区块并迭代交易。我收到一笔交易及其收据。我的代码如下所示:
var tr = web3j.ethGetTransactionByBlockNumberAndIndex(blockIdParam, transactionIndex).sendAsync().get();
var hash = tr.getTransaction().get().getHash();
var receipt = web3.ethGetTransactionReceipt(hash).send().getTransactionReceipt();
Run Code Online (Sandbox Code Playgroud)
现在我正在努力阅读事务日志,检查它们的主题并验证它们是否包含Transfer事件。但是转账事件也是由ERC20交易发出的,所以我在这里有点困惑。
如何在不使用市场解决方案的情况下,在智能合约级别向 Nft 收藏添加版税?
我使用https://github.com/scaffold-eth这个官方存储库来完成我的任务
ethereum ×10
solidity ×6
blockchain ×3
web3js ×3
javascript ×2
metamask ×2
arrays ×1
erc20 ×1
erc721 ×1
ethers.js ×1
go ×1
go-ethereum ×1
java ×1
nft ×1
opensea ×1
transactions ×1
truffle ×1
types ×1
typescript ×1
web3-java ×1