我用这个例子写了Crowdsale .但我无法发送事务,我的测试失败并出现错误:
Contract: Crowdsale should accept payments after start:
AssertionError: expected promise to be fulfilled but it was rejected with 'Error: VM Exception while processing the transaction: revert'
Run Code Online (Sandbox Code Playgroud)
我试图将汽油价格设置为这样的交易,crowdsale.sendTransaction({value, from: buyer, gas: 4712388})但它对我没有帮助.
我的众筹:
pragma solidity ^0.4.16;
interface token {
function transfer(address receiver, uint amount) external;
}
contract Crowdsale {
address public beneficiary;
uint public fundingGoal;
uint public amountRaised;
uint public deadline;
uint public price;
token public tokenReward;
mapping(address => uint256) public balanceOf;
event FundTransfer(address backer, …Run Code Online (Sandbox Code Playgroud) 当我尝试安装 truffle 时,出现以下错误:-
我之前已经安装了 Node.js,并且还安装了 pip。
PS C:\Users\pk199\Documents> npm install -g truffle
npm ERR! code 1
npm ERR! path C:\Users\pk199\AppData\Roaming\npm\node_modules\truffle\node_modules\ganache\node_modules\leveldown
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.3.0
npm ERR! gyp info using node@16.13.1 | win32 | x64
npm ERR! gyp info find Python using Python version 3.10.1 found at "C:\Users\pk199\AppData\Local\Programs\Python\Python310\python.exe"
npm ERR! gyp ERR! find VS
npm …Run Code Online (Sandbox Code Playgroud) I am new to Truffle and going through the Metacoin tutorial; I followed all the steps but when I do truffle compile, I get the following:
Error: Failed to fetch the Solidity compiler from the following locations: https://relay.trufflesuite.com/solc/bin/,https://solc-bin.ethereum.org/bin/,https://ethereum.github.io/solc-bin/bin/. Are you connected to the internet?
Run Code Online (Sandbox Code Playgroud)
I am connected to Internet and using: Truffle v5.5.26 (core: 5.5.26) Ganache v7.4.0 Solidity - 0.8.13 (solc-js) Node v16.13.1 Web3.js v1.7.4
我无法迁移松露编译带来的标准合同.这是我做的:
truffle init
truffle compile
open other terminal and run testrpc
truffle migrate
Run Code Online (Sandbox Code Playgroud)
并且前三步是平稳操作,但是当我运行松露迁移时,它会出现
Error: No network specified. Cannot determine current network.
at Object.detect (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43157:23)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:200497:19
at finished (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43085:9)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:198408:14
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:68162:7
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:163793:9
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:160353:16
at replenish (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:160873:25)
at iterateeCallback (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:160863:17)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:160838:16
Run Code Online (Sandbox Code Playgroud)
我的版本列表:
node 9.1.0
truffle 4.0.1
testrpc 6.0.3
Run Code Online (Sandbox Code Playgroud)
谢谢!
我打算在Hardhat中开发我的智能合约,并在 RSK regtest 本地节点上测试它们。我找到了Truffle regtest 配置。
development: {
host: "127.0.0.1",
port: 4444,
network_id: "*"
},
Run Code Online (Sandbox Code Playgroud)
hardhat.config.js在 RSK regtest 上运行测试需要什么配置?
我有一个关于Solidity合约的函数.例如.
function do(x,y) {
if ( msg.sender != owner )
throw;
// ...
}
Run Code Online (Sandbox Code Playgroud)
在Truffle环境中,我有一个测试js,如:
//.... part of a promise chain
.then(
function (_bool0) {
assert.isTrue(_bool0,"whoops - should be true");
return contract.do( "okdoke" , {from: accounts[1]} );
}).then(
function (tx_id) {
//..
done();
}
// ...
Run Code Online (Sandbox Code Playgroud)
return contract.do()会导致导致throw的条件.在此测试的松露测试输出中产生以下内容:
Error: VM Exception while executing transaction: invalid JUMP
Run Code Online (Sandbox Code Playgroud)
在像这样的测试中处理合同函数抛出的习惯用法是什么?抛出是正确的行为.
所以,我一直在关注 ToDo List 以太坊 DApp 上的 Eat The Blocks 教程。完成第 6 步,但在运行命令时npm run dev-front出现此错误。
> Project@1.0.0 dev-front L:\Project
> ENV=development node_modules/.bin/webpack --watch
'ENV' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Project@1.0.0 dev-front: `ENV=development node_modules/.bin/webpack --watch`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Project@1.0.0 dev-front script.
npm ERR! This is probably not a problem with npm. There …Run Code Online (Sandbox Code Playgroud) 当我使用 truffle 开发智能合约时,每当从 truffle 控制台请求一些数字(例如帐户余额或地址)时;我收到一个 BN 对象,如下所示:
BN {
negative: 0,
words: [ 37748736, 3305132, 2220446, <1 empty item> ],
length: 3,
red: null
}
Run Code Online (Sandbox Code Playgroud)
该对象是bn.js库的一部分。但我无法找到任何有关如何解释该对象的文档。
我怎么读这个。我想了解该对象中每个字段的含义,并能够手动将其转换为正常数字。
我正在构建一个质押功能,并在授予访问我的令牌的权限后遇到以下错误:
“MetaMask - RPC 错误:无法设置未定义的属性(设置“loadingDefaults”)”
Solidity 合约的质押功能:
// Staking function
function depositTokens(uint _amount) public {
require(_amount > 0, 'Amount has to be > 0');
// Transfer tether tokens to this contract
tether.transferFrom(msg.sender, address(this), _amount);
// Update Staking balance
stakingBalance[msg.sender] = stakingBalance[msg.sender] + _amount;
if(!hasStaked[msg.sender]) {
stakers.push(msg.sender);
}
// Update Staking balance
isStaking[msg.sender] = true;
hasStaked[msg.sender] = true;
}
Run Code Online (Sandbox Code Playgroud)
质押前端
stakeTokens = (amount) => {
this.setState({loading: true })
this.state.tether.methods.approve(this.state.deBank._address, amount).send({from: this.state.account}).on('transactionHash', (hash) => {
this.state.deBank.methods.depositTokens(amount).send({from: this.state.account}).on('transactionHash', (hash) => {
this.setState({loading:false})
}) …Run Code Online (Sandbox Code Playgroud) 我正在使用松露部署合同,当我指定气体限制作为我想用于交易的气体时,我总是得到超过气体限制的错误.为什么会这样?
编辑我要做的是将crypto kitties KittyCore.sol合同部署到我的本地devnet.我正在使用松露来部署它.
从另一个页面,如何在使用继承时将松露合同部署到开发网络?,我发现由于存在合同层次结构,我需要按顺序部署合同.我使用了这种技术,并且我能够部署7个合同中的4个,第五个,KittyAuction,给出以下错误:合同代码无法存储,请检查您的燃气量
下面发布的是我的松露部署脚本
var KittyCore = artifacts.require("KittyCore");
var KittyMinting = artifacts.require("KittyMinting");
var KittyAuction = artifacts.require("KittyAuction");
var KittyBreeding = artifacts.require("KittyBreeding");
var KittyOwnership = artifacts.require("KittyOwnership");
var KittyBase = artifacts.require("KittyBase");
var KittyAccessControl = artifacts.require("KittyAccessControl");
var SaleClockAuction = artifacts.require("SaleClockAuction");
module.exports = function (deployer) {
deployer.deploy(KittyAccessControl).then(function () {
return deployer.deploy(KittyBase).then(function () {
return deployer.deploy(KittyOwnership).then(function () {
return deployer.deploy(KittyBreeding).then(function () {
return deployer.deploy(KittyAuction, {
gas: 400000
}).then(function () {
return deployer.deploy(KittyMinting).then(function () {
return deployer.deploy(KittyCore);
})
})
})
})
})
}); …Run Code Online (Sandbox Code Playgroud) truffle ×10
ethereum ×5
solidity ×5
javascript ×2
bignum ×1
blockchain ×1
hardhat ×1
metamask ×1
node.js ×1
npm-install ×1
rsk ×1
webpack ×1