我知道如何从前端传递当前的 Unix 时间:
web3.js:
anchor.web3.SYSVAR_CLOCK_PUBKEY
Run Code Online (Sandbox Code Playgroud)
锈:
let current_time = ctx.accounts.clock.unix_timestamp;
Run Code Online (Sandbox Code Playgroud)
我不要那个。我需要智能合约本身来获取当前时间。
我最近一直在使用测试网,遇到了一些问题:他们经常重置它,服务会关闭几个小时,有时还会出现错误。
我应该使用开发网吗?据我了解,它更稳定,并且重置频率更少?
我有一个使用elrond-sdk-erdjs的 js 后端,我很困惑,因为没有函数可以初始化 https://devnet-gateway.multiversx.com ,只有测试网。有理由吗?
// TODO: Adjust with respect to current terminology (localnet instead of devnet).
function getDevnetProvider() {
return new proxyProvider_1.ProxyProvider("http://localhost:7950", { timeout: 5000 });
}
exports.getDevnetProvider = getDevnetProvider;
function getTestnetProvider() {
return new proxyProvider_1.ProxyProvider("https://testnet-gateway.elrond.com", { timeout: 5000 });
}
exports.getTestnetProvider = getTestnetProvider;
function getMainnetProvider() {
return new proxyProvider_1.ProxyProvider("https://gateway.elrond.com", { timeout: 20000 });
}
Run Code Online (Sandbox Code Playgroud) 返回错误:处理交易时 VM 异常:恢复 ERC20:转账金额超出限额
代码:
ERC20Tokens[tokenTicker].token.approve(ERC20Tokens[tokenTicker].tokenHolder, 10);
emit tokenOwnerBalance(ERC20Tokens[tokenTicker].token.balanceOf(ERC20Tokens[tokenTicker].tokenHolder));
ERC20Tokens[tokenTicker].token.transferFrom(ERC20Tokens[tokenTicker].tokenHolder, address(this), 1);
Run Code Online (Sandbox Code Playgroud)
日志:
[
{
"from":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"topic":"0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925",
"event":"Approval",
"args":{
"0":"0x7A2946b37399fa3F1C9EF81c7Bcf94AE1099D18F",
"1":"0x95Ba4cF87D6723ad9C0Db21737D862bE80e93911",
"2":"10",
"owner":"0x7A2946b37399fa3F1C9EF81c7Bcf94AE1099D18F",
"spender":"0x95Ba4cF87D6723ad9C0Db21737D862bE80e93911",
"value":"10"
}
},
{
"from":"0x7A2946b37399fa3F1C9EF81c7Bcf94AE1099D18F",
"topic":"0xcff530ae4ada35c1dd7ac314ef643b9eb7ae40665958ad5899e2fbc18865444a",
"event":"tokenOwnerBalance",
"args":{
"0":"31000000"
}
}
]
Run Code Online (Sandbox Code Playgroud) 如果我想获取给定钱包地址的英雄标签,我可以简单地调用以下端点:
https://api.elrond.com/accounts/erd1hw78kxyj353x52hmmq6dzxgexynwt4m29q2uvpq6xdm90z3halvsl7cn6g
我得到:
{
"address":"erd1hw78kxyj353x52hmmq6dzxgexynwt4m29q2uvpq6xdm90z3halvsl7cn6g",
"nonce":4,
"balance":"0",
"rootHash":"QU6o17Qw4KUPnpU6e6QbEuvKUTA8SPy52QFseslWsG4=",
"txCount":4,
"username":"event.elrond",
"shard":1
}
Run Code Online (Sandbox Code Playgroud)
我在哪里看到username.
但现在我想获取给定英雄标签的钱包地址。
是否有用于此目的的 API 端点?
我想迭代以太坊 ERC-721 合约的所有代币 ID。有些合约有计数 id (0, 1, 2, 3, ...),这很容易,但有些合约有随机 id,例如https://etherscan.io/token/0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d#inventory
遗憾的是 etherscan 只显示最后使用的 10000 个令牌 id,但我想迭代所有 79490 个。有没有办法实现这一点?对我来说,一切都很好。使用一些 API 设置我自己的以太坊节点。
编译 .\src\contracts\Migrations.sol 编译 .\src\contracts\Migrations.sol 编译 .\src\contracts\Tether.sol
编译 .\src\contracts\Tether.sol
工件写入 D:\Projects\ANIS\ Decentralized_Bank\src\truffle_abis 使用以下命令成功编译:
正在编译您的合同...
at C:\Users\OMEN\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\workflow-compile\index.js:28:1
at Array.map (<anonymous>)
at compile (C:\Users\OMEN\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\workflow-compile\index.js:26:1)
at Object.compile (C:\Users\OMEN\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\workflow-compile\index.js:68:47)
at Object.compileAndSave (C:\Users\OMEN\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\workflow-compile\index.js:95:47)
at Object.run (C:\Users\OMEN\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:199:1)
at Command.run (C:\Users\OMEN\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\command.js:183:1)
Run Code Online (Sandbox Code Playgroud)
Truffle v5.4.11(核心:5.4.11)节点 v14.17.2
我在重新混合时遇到此错误:
函数调用中参数的类型无效。从地址到请求的应付地址的隐式转换无效
它指的是msg.sender下面的第 9 行。这是我正在编写的代码:
function startProject(
string calldata title,
string calldata description,
uint durationInDays,
uint amountToRaise
) external {
uint raiseUntil = block.timestamp.add(durationInDays.mul(1 days));
Project newProject = new Project(
msg.sender,
title,
description,
raiseUntil,
amountToRaise
);
projects.push(newProject);
Run Code Online (Sandbox Code Playgroud)
为什么我会收到此错误?我该如何解决?
我正在 YouTube 上学习freeCodeCamp课程,在运行该程序时发现了一个错误。当我试图在 Ganache 中建立一个交易时。我在 Ganache 日志中看到也有活动。第一次发帖,请告诉我还应该提供哪些信息!
\n课程:Solidity、区块链和智能合约课程 \xe2\x80\x93 初学者到专家 Python 教程
\ntransaction = SimpleStorage.constructor().buildTransaction(\n {"chainId": chain_id, "from": my_address, "nonce": nonce}\n)\nRun Code Online (Sandbox Code Playgroud)\n终端返回的错误:
\ntransaction = SimpleStorage.constructor().buildTransaction(\n {"chainId": chain_id, "from": my_address, "nonce": nonce}\n)\nRun Code Online (Sandbox Code Playgroud)\n我使用的完整代码如下:
\nfrom solcx import compile_standard, install_solc\nimport json\nfrom web3 import Web3\n\nwith open("./SimpleStorage.sol", "r") as file:\n simple_storage_file = file.read()\n\n# Compile Our Solidity\nprint("Installing...")\ninstall_solc("0.6.0")\n\ncompiled_sol = compile_standard(\n {\n "language": "Solidity",\n "sources": {"SimpleStorage.sol": {"content": simple_storage_file}},\n "settings": {\n "outputSelection": {\n "*": {\n "*": [\n "abi",\n "metadata",\n "evm.bytecode",\n …Run Code Online (Sandbox Code Playgroud) 我正在使用 BSC 分叉在安全帽网络上测试我的合约。
我正在部署具有铸币功能的代币合约:
// @dev Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef).
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
Run Code Online (Sandbox Code Playgroud)
然后我将其部署到测试中> npx hardhat test,它将运行此代码的测试:
...
it("Should deploy", async () => {
token = await Token.deploy();
await token.deployed();
console.debug(`\t\t\tToken Contract Address: ${cyan}`, token.address);
const supply = await token.totalSupply()
console.debug(`\t\t\tToken totalSupply: ${yellow}`, supply);
await token.mint(owner.address, web3.utils.toWei("1000", 'ether'))
console.debug(`\t\t\tToken owner balance: ${cyan}`, token.balanceOf(owner.address));
});
...
Run Code Online (Sandbox Code Playgroud)
测试正确打印前 2 …
我需要获取代币从特定时间到最近一轮的 Chainlink 价格。该时间根据用户输入而变化,但根据令牌的心跳,窗口期相对较短(最多 1 天到 2 周)。这用于计算智能合约和应用程序主页上的支付价格。
为了获取历史价格数据,Chainlink 需要一个“roundId”,它是一个非增量值。
从 Chainlink 获取给定时间窗口的所有 roundId 或以开放、去中心化且可在 Solidity 智能合约中访问的方式记录它们的最佳方法是什么?
blockchain ×10
solidity ×4
ethereum ×3
javascript ×2
multiversx ×2
chainlink ×1
deployment ×1
erc20 ×1
ganache ×1
hardhat ×1
nft ×1
python ×1
remix ×1
rust ×1
solana ×1
thegraph ×1
truffle ×1
web3js ×1
web3py ×1