标签: ethereum

Solidity v^0.5.0 编译器错误 [指定的回调无效]

我正在尝试编译我的合同,但出现此错误:

AssertionError [ERR_ASSERTION]: Invalid callback specified.
Run Code Online (Sandbox Code Playgroud)

一种答案是更改编译器的版本,但我的版本是最新的(0.5.0)。我实际上正在尝试使用旧代码(0.4.17)并升级它。尝试了2天,一直失败。

这是我的合同:

pragma solidity ^0.5.0;

contract Lottery{
 address public manager;
 address payable [] public players;

 modifier restricted {
     require(msg.sender == manager);
     _;
 }

 constructor() public {
     manager = msg.sender;
 }

 function participate() public payable {
     require(msg.value > .01 ether);
     players.push(msg.sender);
 }

 function pseudoRandom() private view returns(uint){
     return uint(keccak256(abi.encodePacked(block.difficulty, now, players)));
 }

 function pickWinner() public restricted {
     require(msg.sender == manager);
     uint index = pseudoRandom() % players.length;
     address(players[index]).transfer(address(this).balance);
     (players) = new address payable[](0);
 }

 function getPlayers() …
Run Code Online (Sandbox Code Playgroud)

ethereum solidity

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

如何使用 solc 0.5 编译 Solidity

编译.js:

const path = require('path');
const solc = require('solc');
const fs = require('fs-extra');

const buildPath = path.resolve(__dirname, 'build');
fs.removeSync(buildPath);

const campaignPath = path.resolve(__dirname, 'contracts', 'Campaign.sol');
const source = fs.readFileSync(campaignPath, 'utf8');

var input = {
    language: 'Solidity',
    sources: {
        'Campaign.sol': {
            content: source
        }
    },
    settings: {
        outputSelection: {
            '*': {
                '*': [ '*' ]
            }
        }
    }
}

const output = solc.compile(input, 1).contracts;

fs.ensureDirSync(buildPath);

for(let contract in output){
    fs.outputJSONSync(
        path.resolve(buildPath, contract+'.json')
    );
}
Run Code Online (Sandbox Code Playgroud)

活动.sol:

pragma solidity ^0.5.3;

contract FactoryCampaign { …
Run Code Online (Sandbox Code Playgroud)

javascript ethereum solidity smartcontracts

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

如何解析 Nethereum 中的签名交易?

我使用 进行了交易TransactionSigner.SignTransaction(...),并将其存储以供将来参考。我如何解析它以获得公钥/源钱包地址、目标地址、随机数和 Wei 金额?

我尝试在 GitHub 存储库中搜索Parse方法,但没有找到用于事务的方法。

c# ethereum nethereum

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

如何在 Solidity 中声明常量

我对 Solidity 和智能合约非常陌生,非常感谢一些帮助。我正在遵循教程,这就是他们使用的确切代码。但是当我编译代码时,我收到此错误:

ParserError:预期的主表达式。地址公共常量​​批准者 = ;

pragma solidity ^0.6.0;

contract ApprovalContract {

    address public sender;
    address public receiver;
    address public constant approver = ;

    function deposit(address _receiver) external payable {
        require(msg.value > 0);
        sender = msg.sender;
        receiver = _receiver;
    }

    function viewApprover() external pure returns(address) {
        return(approver);
    }

    function approve() external {
        require(msg.sender == approver);
        receiver.transfer(address(this).balance);
    }
}
Run Code Online (Sandbox Code Playgroud)

ethereum solidity smartcontracts truffle

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

web3.eth.accounts[0] 返回未定义并且 app.vote(1,{ from:web3.eth.accounts[0] }) 给出错误

我对 Solidity 很陌生,正在通过一个简单的网络应用程序来探索它。我正在尝试制作一个候选人投票网络应用程序,它接受一些详细信息和一个按钮,按下该按钮应将详细信息部署到智能合约创建的块中。当我尝试web3.eth.accounts[0]在 truffle console 中使用帐户详细信息时,它返回 undefined 。当我尝试使用 truffle 控制台从帐户 1 向候选人 1 发送选票时app.vote(1,{ from:web3.eth.accounts[0] }),我收到如下错误:

truffle(development)> web3.eth.accounts[0]
undefined
truffle(development)> app.vote(1,{ 
from:web3.eth.accounts[0] })
Thrown:
Error: The send transactions "from" field 
must be defined!
at evalmachine.<anonymous>:0:5
at sigintHandlersWrap (vm.js:272:15)
at Script.runInContext (vm.js:127:14)
at runScript
at bound (domain.js:426:14)
    at REPLServer.runBound [as eval] (domain.js:439:12)
    at REPLServer.onLine (repl.js:726:10)
    at REPLServer.emit (events.js:219:5)
    at REPLServer.EventEmitter.emit (domain.js:482:12)
    at REPLServer.Interface._onLine (readline.js:324:10)
    at REPLServer.Interface._line (readline.js:701:8)
    at REPLServer.Interface._ttyWrite (readline.js:1026:14)
    at REPLServer.self._ttyWrite (repl.js:803:7)
    at ReadStream.onkeypress (readline.js:200:10)
    at …
Run Code Online (Sandbox Code Playgroud)

javascript ethereum solidity web3js metamask

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

是否可以过滤以太坊的待处理交易?

为了获取我的节点所知道的待处理事务的列表,我可以轻松地调用eth_pendingTransactionsjRPC 调用。这将给出一个待处理事务的大列表,所有这些都需要解析以找到客户端关心的待处理事务。

是否可以预先过滤交易?有eth_newpendingtransactionfilter什么帮助https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newpendingtransactionfilter吗?我似乎无法理解这与待处理交易有何关系。

rpc json-rpc ethereum

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

生成以太坊支付网关地址

我想在我的网站上添加“用以太坊付款”功能,我知道在以太坊中我们有一个 HD 钱包,它为我们提供了一些帐户,但我不知道对于付款之类的东西,我是否应该每次为新发票生成新帐户?然后将以太币转入主账户?智能合约是否参与该解决方案。

我使用 dotnet core (c#) 、 ganache 作为测试链和 nethereum 。

c# ethereum cryptocurrency

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

如何使用 UniswapV2Router02 合约通过 swapExactTokensForETH() 将代币交换为 ETH

我打算使用 Etherscan(Ropsten 测试网络)上的 UniswapV2Router02 在 Ropsten 网络上将一些 DAI 兑换为 ETH。

Ropsten 上的 DAI 地址 = 0xad6d458402f60fd3bd25163575031acdce07538d WETH = 0xc778417E063141139Fce010982780140Aa0cD5Ab

我的钱包里有 2000 DAI (Ropsten)

但是当我把数据放在那里时。像这样: 在此输入图像描述

Metamask 显示合约抛出了一个错误。所以我可能错过了一些东西或者我做错了。

在此输入图像描述

请有人帮助并告诉我如何才能在那里成功交易?

ethereum smartcontracts web3js etherscan

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

执行简单合约时,Geth 私网返回错误“invalid opcode: SELFBALANCE”

我设置了一个简单的 Geth (v1.10.2-stable-97d11b01) 专用网络(genesis.json配置如下)。我编译并部署了这个简单的测试合约(solidity版本:0.8.4+commit.c7e474f2.Emscripten.clang):

// SPDX-License-Identifier: UNLICENSED;
pragma solidity >=0.8;

contract CoinA {
    
    bytes32 public coinName = "FAKE";

    mapping (address => uint) public balances;

    function transfer(address receiver, uint amount) public {
        require(balances[msg.sender] >= amount, "Not enough amount");
        
        balances[msg.sender] -= amount;
        balances[receiver] += amount;
    }

    function set(uint amount) public {
        require(amount >= 0);
        balances[msg.sender] = amount;
    }

    function get() view public returns (uint) {
        return balances[msg.sender];
    }

}
Run Code Online (Sandbox Code Playgroud)

但是,在调用该set方法时,我收到此错误:

UnhandledPromiseRejectionWarning:错误:返回错误:无效操作码:SELFBALANCE

请建议如何解决这个问题。是因为服务器没有支持该操作码的最新功能吗?无论如何,我可以在不使用该操作码的情况下编译代码吗?

如果相关的话,我在 Node 上使用 Web3JS 调用它:

    async …
Run Code Online (Sandbox Code Playgroud)

blockchain ethereum solidity smartcontracts geth

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

以太坊智能合约批准另一个合约的支出者

我有一个 erc20 代币,在另一个合约中我想创建一个代币交换功能。所以很容易,发送一个 usdc 代币并以 1:1 的比例交换我的 erc20 代币。问题是如何批准使用我的 erc20 代币。我尝试了几次但找不到方法。

interface IERC20 {...} 

contract AnotherContract {

function approve(address _spender, uint256 _amount) public returns(bool) {
    return IERC20(MyToken).approve(_spender, _amount);
}
Run Code Online (Sandbox Code Playgroud)

我部署了另一个合同,当我从中调用批准功能时。所以当我将“_spender”设置为这个合约地址时。结果很奇怪。所以这个合约既是所有者又是消费者。我认为用户应该是所有者,而这个合约应该是消费者。但是函数是从链上调用的。msg.sender 将是该合约地址本身。

我不明白并且很困惑。有人知道或者有一些资源吗?谢谢。

blockchain ethereum solidity smartcontracts binance-smart-chain

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