标签: solidity

没有源代码是否可以获取合约的ABI?

是否可以在没有源代码的情况下获取已知合约地址的ABI?

我发现的唯一方法是使用 etherscan 的 API,但它仅适用于经过验证的合约。

blockchain ethereum solidity web3js

1
推荐指数
1
解决办法
1万
查看次数

在满足请求时在 Chainlink 节点上恢复交易

我的 Chainlink 节点上的交易已恢复,我正在寻找一些有关如何调试它的提示。节点接收 Oracle 请求并且作业成功运行。我的履行功能很小:

function checkConditions(address _oracle, string memory _jobId) external {
    setPublicChainlinkToken();
    Chainlink.Request memory request = buildChainlinkRequest(
        stringToBytes32(_jobId),
        address(this),
        this.fulfill.selector
    );

    request.add("ytChannelId", "UCfpnY5NnBl-8L7SvICuYkYQ");
    sendChainlinkRequestTo(
        _oracle,
        request,
        1 * LINK_DIVISIBILITY
    );
}

event OnFulfill(uint256 _ytViews, uint256 _ytSubs);

function fulfill(
    bytes32 _requestId,
    uint256 _ytViews,
    uint256 _ytSubs
) public recordChainlinkFulfillment(_requestId) {
    emit OnFulfill(_ytViews, _ytSubs);
}
Run Code Online (Sandbox Code Playgroud)

我从这个github blob改编了作业规范,因为它是一个带有桥的多变量作业,这正是我的用例。我的 .toml 文件:

type = "directrequest"
schemaVersion = 1
name = "mysocialcontract-ea-job"
contractAddress = "0x2Db11F9E1d0a1cDc4e3F4C75B4c14f4a4a1a3518"
maxTaskDuration = "0s"
observationSource = """
    decode_log   [type="ethabidecodelog"
                  abi="OracleRequest(bytes32 …
Run Code Online (Sandbox Code Playgroud)

solidity chainlink

1
推荐指数
1
解决办法
364
查看次数

在 Solidity 中是否有一种有效的方法将字符串数组连接成单个字符串?

我的目标是编写一个函数,它接受一个字符串数组,并返回一个包含所有输入字符串组合的字符串。

例如,在 Python 中可以这样完成:

result = ''.join(['hello', 'solidity', 'world'])  # hellosolidityworld
Run Code Online (Sandbox Code Playgroud)

我当前的实现似乎根本没有效率:

function concat(string[] memory words) internal pure returns (string memory) {
    // calculate output length
    uint256 bytesLength;
    for (uint256 i = 0; i < words.length; i++) {
        bytesLength += bytes(words[i]).length;
    }

    bytes memory output = new bytes(bytesLength);
    uint256 currentByte;

    for (uint256 i = 0; i < words.length; i++) {
        bytes memory bytesWord = bytes(words[i]);
        for (uint256 j = 0; j < bytesWord.length; j++) {
            output[currentByte] = bytesWord[j];
            currentByte++;
        } …
Run Code Online (Sandbox Code Playgroud)

solidity

1
推荐指数
1
解决办法
2444
查看次数

WalletBalance.tsx 代币余额返回:未定义

我已经完成了全栈 defi 课程,当我使用usedapp/core 中的 useTokenBalance 函数时,我没有返回任何内容,我不知道我哪里出了问题,因为当我 console.log 地址时以及它返回的帐户变量以及正确的帐户地址和正确的令牌地址。 在此输入图像描述

这是这里的打字稿:

import {useEthers, useTokenBalance} from "@usedapp/core"
import {formatUnits} from "@ethersproject/units"

export interface WalletBalanceProps {
    token: Token
}

export const WalletBalance = ({token}: WalletBalanceProps) => {
    const {image, address, name} = token
    const {account} = useEthers()
    console.log(account)
    console.log(address)
    const tokenBalance = useTokenBalance(address, account)
    const formattedTokenBalance: number = tokenBalance ? parseFloat(formatUnits(tokenBalance, 18)) : 0
    console.log(tokenBalance?.toString())
    return (<div>{formattedTokenBalance}</div>)
}
Run Code Online (Sandbox Code Playgroud)

我认为这可能是 @usedapp/core 的错误,但我重新安装了 @usedapp/core 并且仍然返回相同的错误。任何帮助都会有用的:)

typescript solidity brownie usedapp

1
推荐指数
1
解决办法
488
查看次数

将版税添加到 Solidity NFT 智能合约中

如何在不使用市场解决方案的情况下,在智能合约级别向 Nft 收藏添加版税?

我使用https://github.com/scaffold-eth这个官方存储库来完成我的任务

blockchain ethereum solidity smartcontracts nft

1
推荐指数
1
解决办法
2545
查看次数

使用 Hardhat 部署智能合约时出错 - 错误 HH9:加载 Hardhat 配置时出错

尝试使用 Hardhat 部署智能合约但出现配置错误。

这是完整的错误详细信息

Error HH9: Error while loading Hardhat's configuration.
You probably tried to import the "hardhat" module from your config or a file imported from it.
This is not possible, as Hardhat can't be initialized while its config is being defined.
Run Code Online (Sandbox Code Playgroud)

所有插件似乎都已正确安装。

部署.js

const hre = require("hardhat");

async function main() {
  const TestContract = await hre.ethers.getContractFactory("TestContract");
  const superInstance = await TestContract.deploy("TestContractHAT", "SMC");
  await superInstance.deployed();
  console.log("contract was deployed to:", superInstance.address());
}

// We recommend this pattern to be able …
Run Code Online (Sandbox Code Playgroud)

solidity smartcontracts hardhat

1
推荐指数
1
解决办法
4414
查看次数

Ethers.js:如何将地址数组编码到 Solidity 字节变量中?

我正在使用 Ether.js 测试我的 Solidity 代码,并且被测试的方法需要一个bytes参数,我用它来传递地址数组:

function testFunction(bytes calldata params) external {
   address[] memory addresses = abi.decode(params, (address[]));
}
Run Code Online (Sandbox Code Playgroud)

如何在 Ethers.js 中对地址数组进行编码,以便可以将其作为参数传递?

encode solidity ethers.js

1
推荐指数
1
解决办法
1万
查看次数

如何从 chainlink VRF V2 获取 10000 个随机数?

我想使用 chainlink VRF V2 生成 10000 个随机数,但一次请求的最大 NUM_WORDS 为 500,每次都失败\xef\xbc\x81\n我该怎么办?\n我的帐户有足够的 LINK,但我怎么办?做了下面的不起作用!

\n
// SPDX-License-Identifier: MIT\npragma solidity ^0.8.8;\n\nimport "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";\nimport "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";\n\ncontract VRFCoordinatorTest is  VRFConsumerBaseV2 {\n    // Chainlink VRF Variables\n\n    address vrfCoordinatorV2 = 0x6168499c0cFfCaCD319c818142124B7A15E857ab;\n    uint64 subscriptionId = 14422;\n    bytes32 gasLane = 0xd89b2bf150e3b9e13446986e571fb9cab24b13cea0a43ea20a6049a85cc807cc;\n    uint32 public callbackGasLimit = 2500000; //already max gaslimit\n\n    //network coordinator\n    VRFCoordinatorV2Interface private immutable _vrfCoordinator;\n\n    // The default is 3, but you can set this higher.\n    uint16 public  REQUEST_CONFIRMATIONS = 10;\n\n    // retrieve NUM_WORDS random values in one request.\n    uint32 public NUM_WORDS …
Run Code Online (Sandbox Code Playgroud)

random solidity smartcontracts chainlink

1
推荐指数
1
解决办法
842
查看次数

错误:合约运行程序不支持在 ethers.js v6 上调用(操作 =“call”,代码 = UNSUPPORTED_OPERATION,版本 = 6.3.0)

我正在使用ReactHardhatEthers.jsSolidity制作一个简单的 dapp 。

我一直在关注 YouTube 上的教程,但我陷入了从创建的合约对象调用 Solidity 函数的部分。

每当我尝试从合约中调用函数时,它都会不断产生以下错误:

"contract runner does not support calling"
Run Code Online (Sandbox Code Playgroud)

查询合约是有效的,因为我可以获得合约的余额,但我找不到任何有关如何修复合约运行程序错误的资源。将不胜感激的帮助。下面是 React 中的代码。

"contract runner does not support calling"
Run Code Online (Sandbox Code Playgroud)

坚固性代码:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

contract Rental {
    struct Bike{
        string name;
        uint rangePower;
        uint maxSpeed;
        uint batteryCapacity;
        uint costPerHour;
        bool isAvailable;
    }
    
    //admin variables
    address owner;
    uint totalHours=0;
    uint totalRents=0;
    uint totalEbikes;

    //array of bikes
    Bike[] bikes;
 
    constructor(){
        //contract deployer address
        owner = msg.sender;

        //initialization …
Run Code Online (Sandbox Code Playgroud)

solidity decentralized-applications ethers.js hardhat

1
推荐指数
1
解决办法
4855
查看次数

Solidity 类型地址不可转换为 uint256 类型

我创建了一个结构数组,然后尝试获取数组中每个帐户的值。但是我在传递包含地址变量的数组时失败了,msg.sender并且类型不能明显地转换为uint256. 我该怎么做?

solidity

0
推荐指数
2
解决办法
2860
查看次数