标签: truffle

松露控制台变量声明

当我尝试进入以太坊编程时,我目前正在关注本教程(https://medium.com/zeppelin-blog/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05)。步骤3与已部署的合同进行交互。

当我进入

truffle(default)> var poe = ProofOfExistence1.deployed()
Run Code Online (Sandbox Code Playgroud)

结果是“未定义”,并且也无法与以下命令进行交互。我肯定部署了合同,因为

truffle(development)> ProofOfExistence1.deployed()
Run Code Online (Sandbox Code Playgroud)

获取输出并列出合同内的所有功能等。使用testrpc和geth testnet进行了尝试,所以我想这与松露有关吗?

ethereum solidity truffle

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

正确使用artifacts.require?

我想了解artifacts.require应该如何使用.我已经看到标准段落将其描述为迁移和测试.由此我推断,在进行迁移或运行测试时,松散可执行工具会自动定义artifacts其方法的全局作用域require.但是,我正在使用一些artifacts.require在任何迁移或测试的上下文之外使用的代码,相反,这段代码只需要执行常规atnew.但是,在此上下文中,artifacts未定义对象.

我在这里有合适的照片吗?这是一个合适的用途artifacts.require吗?如果是这样,必须采取哪些措施才能在迁移和测试之外进行定义?

谢谢你的任何建议!

truffle

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

合约尚未部署到 Rinkeby Network 上检测到的网络(网络/工件不匹配)

我一直遇到标题中指定的。

我开发了一个智能合约并成功编译并部署到网络如下: 1. 运行 testrpc 2. truffle compile 3. truffle migrate

但是,仍然显示上述错误。然后我尝试删除构建文件并按照以下步骤操作: 1. 运行 testrpc 2. truffle compile 3. truffle migrate --network rinkeby

错误仍然显示。

下面是 truffle.js 文件

module.exports = {
  migrations_directory: "./migrations",
  networks: {
development: {
  host: "localhost",
  port: 8545,
  network_id: "*" // Match any network id
},
rinkeby: {
  host: "localhost", // Connect to geth on the specified
  port: 8545, 
  network_id: "*",
}
Run Code Online (Sandbox Code Playgroud)

} };

如果有人遇到任何类似的问题并已解决,如果您能分享您是如何解决的,我将不胜感激。

提前致谢

ethereum smartcontracts truffle consensys-truffle

5
推荐指数
3
解决办法
8619
查看次数

如何在松露中手动创建合同实例

说我有2个像这样的合同

A.sol
import './B.sol';
contract A {
    event BCreated(address addressOfB);
    function createB(){
        B b = new B();   
        BCreated(b);
    }
}


B.sol
contract B {    
    uint8 value = 5;
    function getValue() constant returns(uint8){
        return value;
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试为这些合同编写测试用例.我可以使用迁移文件部署合同A,并获取它的实例.

但是在使用函数createB()创建合同之后,我不确定如何获得合同B的实例

好的,我可以在调用函数createB()后得到事件中合约B的地址,但不确定实例.

对于这个例子,你可以说我可以单独测试合同B,因为它没有做太多.但在实际情况中,我需要使用来自事件的地址创建实例.

这里是松露测试文件的一点点js代码在这里我有B的地址

var A = artifacts.require("./A.sol");
contract('A', (accounts) => {
    it("Value should be 5", async () => {
        let instanceOfA = await A.deployed()
        let resultTx = await instanceOfA.createB({ from: accounts[0] });
        console.log("Address of B: " + resultTx.logs[0].args.addressOfB);
        /**
         * How do …
Run Code Online (Sandbox Code Playgroud)

ethereum solidity truffle

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

松露 - 有没有办法自动生成测试用例?

有没有办法在Truffle中自动生成测试用例?

例如,AutoFixture库帮助我在xUnit中自动生成测试用例.我正在寻找类似的功能.

javascript unit-testing mocha.js solidity truffle

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

npm 错误“Keccak 绑定编译失败。” 在安装松露时

我尝试安装 Truffle,但随后出现此错误:

$ npm install -g truffle
    C:\Users\dany.vandermeij\AppData\Roaming\npm\truffle -> C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js

> keccak@1.4.0 install C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\node_modules\keccak
> npm run rebuild || echo "Keccak bindings compilation fail. Pure JS implementation will be used."


> keccak@1.4.0 rebuild C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\node_modules\keccak
> node-gyp rebuild


C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\node_modules\keccak>if not defined npm_config_node_gyp (node "C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\dany.vandermeij\AppData\Local\Programs\Python\Python37-32\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; …
Run Code Online (Sandbox Code Playgroud)

node.js npm keccak npm-install truffle

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

Openzeppelin SDK 和 Truffle 的区别?

对于智能合约开发,Openzeppelin SDK 和 Truffle 有什么区别?我什么时候应该使用一种或另一种,或两者一起使用?

ethereum smartcontracts truffle openzeppelin

5
推荐指数
2
解决办法
1282
查看次数

为什么不可能使用 Truffle 部署智能合约(到主网)?

为什么使用 Truffle 部署到主网如此困难?

这是尝试部署到主网的概述......

  1. 当前 Gasprice 为 110 威。所以110000000000 wei

让我们插上它..

mainnet: {
      provider: () =>
        new HDWalletProvider({
          mnemonic: { phrase: process.env.MNEMONIC },
          providerOrUrl: process.env.RPC_URL_1_WSS,
        }),
      network_id: 1, 
      from: process.env.DEPLOYERS_ADDRESS,
      gasPrice: 110000000000, /*  GAS PRICE!! */
      confirmations: 2,
      timeoutBlocks: 200,
      skipDryRun: false, public nets )
    },
  },
Run Code Online (Sandbox Code Playgroud)
  1. 让我们来估算一下部署的 gas 成本。这将在 的gas参数中设置truffle-config

NODE_ENV=production truffle migrate --network mainnet --dry-run

Summary
=======
> Total deployments:   2
> Final cost:          0.001403824 ETH
Run Code Online (Sandbox Code Playgroud)

0.001403824 ETH 是 2.04 美元。
所以这很可能是错误的。

??失败?? …

ethereum smartcontracts truffle consensys-truffle

5
推荐指数
0
解决办法
410
查看次数

npm 为以太坊开发安装 truffle 时出错

当我尝试使用安装 truffle 时npm,会出现以下输出:

npm WARN deprecated mkdirp-promise@5.0.1: This package is broken and no longer maintained. 'mkdirp' itself supports promises now, please switch to that.

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142

npm WARN deprecated har-validator@5.1.5: this library is no longer supported

npm WARN deprecated multicodec@0.5.7: stable api reached

npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated

npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated

npm WARN deprecated mkdirp@0.5.1: Legacy versions of mkdirp are no longer supported. Please update to …
Run Code Online (Sandbox Code Playgroud)

linux npm-install truffle

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

“迁移”在部署时遇到无效的操作码

当我执行“松露部署”命令时,我突然开始收到“部署时迁移遇到无效操作码”错误。

\n

我的迁移文件没有更改,所以我不确定为什么突然收到此错误。每个发布相同错误的人都只是建议下载最新版本的 ganache/truffle,但我已将我的 truffle 和 ganache 更新到最新版本,但仍然收到错误。

\n

这是完整的错误:\n\xe2\xa0\x8b 从 solc-bin 获取 solc 版本列表。尝试 #1\n开始迁移...

\n
\n

网络名称:'development'\n网络 ID:5777\n区块 Gas 限制:6721975 (0x6691b7)

\n
\n

1_initial_migration.js

\n

\xe2\xa0\x99 从 solc-bin 获取 solc 版本列表。尝试#1\n部署“迁移”

\n

*** 从 solc-bin 部署***失败。尝试#1

\n

“迁移”在部署时遇到无效的操作码。尝试:

\n
    \n
  • 验证您的构造函数参数是否满足所有断言条件。
  • \n
  • 验证构造函数代码不会越界访问数组。
  • \n
  • 将原因字符串添加到断言语句中。
  • \n
\n

退出:通过在 Etherscan 上检查上面的交易哈希值来手动查看成功的交易。

\n

错误:*** 部署失败 ***

\n

“迁移”在部署时遇到无效的操作码。尝试:

\n
    \n
  • 验证您的构造函数参数是否满足所有断言条件。
  • \n
  • 验证构造函数代码不会越界访问数组。
  • \n
  • 将原因字符串添加到断言语句中。
  • \n
\n
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:330:1\n
Run Code Online (Sandbox Code Playgroud)\n

Truffle v5.9.2(核心:5.9.2)\nNode v18.7.0

\n

迁移.sol

\n
// SPDX-License-Identifier: MIT\npragma solidity …
Run Code Online (Sandbox Code Playgroud)

javascript ethereum solidity truffle ganache

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