Итак, я начал изучать блокчейн. Я использовал trufflesuite, начал с базового кода, который предоставляет трюфель: truffle unbox metacoin
Далее я развернул Ganache: testrpc
и отправил миграцию в Ganache truffle migration
. В базовом коде они предоставляют 2. js файла: 1_initial_migration. js
const Migrations = artifacts.require("Migrations");
module.exports = function(deployer) {
deployer.deploy(Migrations);
};
И 2_deploy_contracts. js
const ConvertLib = artifacts.require("ConvertLib");
const MetaCoin = artifacts.require("MetaCoin");
module.exports = function(deployer) {
deployer.deploy(ConvertLib);
deployer.link(ConvertLib, MetaCoin);
deployer.deploy(MetaCoin);
};
Следующая ошибка возникает, когда я перебрасываю трюфель на Ганаш:
На консоли:
security / no -tx-origin: рассмотрите возможность использования «msg.sender» вместо «tx.origin».
На терминале, где я запускаю миграцию трюфелей:
Compiling your contracts...
===========================
> Compiling ./contracts/ConvertLib.sol
> Compiling ./contracts/MetaCoin.sol
> Compiling ./contracts/Migrations.sol
> Artifacts written to /home/sergio/github/Apuntalo/Apuntalo/blockchain/truffleproject/build/contracts
> Compiled successfully using:
- solc: 0.5.16+commit.9c3226ce.Emscripten.clang
Starting migrations...
======================
> Network name: 'development'
> Network id: 1584460773335
> Block gas limit: 0x6691b7
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
> transaction hash: 0x39a5524845bf0deba57b208a8aa80b9967f16d69e8eba66bb1760355d9ff9424
> Blocks: 0 Seconds: 0
> contract address: 0x8393bEdea418648c69cB502536c68D88fA9EEA03
> block number: 3
> block timestamp: 1584460824
> account: 0xa6b143C88CA658C9d2De18CdefE2Fc2F52c77E81
> balance: 99.85802118
> gas used: 188483
> gas price: 20 gwei
> value sent: 0 ETH
> total cost: 0.00376966 ETH
⠹ Saving migration to chain.
Error: Returned error: VM Exception while processing transaction: invalid opcode at PromiEvent (/usr/local/lib/node_modules/truffle/build/webpack:/packages/contract/lib/promievent.js:9:1)
at TruffleContract.setCompleted (/usr/local/lib/node_modules/truffle/build/webpack:/packages/contract/lib/execute.js:169:1)
at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/migration.js:93:1)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/migration.js:57:1)
at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/migration.js:167:1)
at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:148:1)
at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:87:1)
at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:253:1)
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:218:1
Truffle v5.1.17 (core: 5.1.17)
Node v13.11.0
Появляется быть ошибкой в файле MetaCoin.sol, в его конструкторе.
security / no-tx-origin: рассмотрите возможность использования msg.sender вместо tx.origin.
MetaCoin.sol:
pragma solidity >=0.4.25 <0.7.0;
import "./ConvertLib.sol";
// This is just a simple example of a coin-like contract.
// It is not standards compatible and cannot be expected to talk to other
// coin/token contracts. If you want to create a standards-compliant
// token, see: https://github.com/ConsenSys/Tokens. Cheers!
contract MetaCoin {
mapping (address => uint) balances;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
constructor() public {
balances[tx.origin] = 10000;
}
function sendCoin(address receiver, uint amount) public returns(bool sufficient) {
if (balances[msg.sender] < amount) return false;
balances[msg.sender] -= amount;
balances[receiver] += amount;
emit Transfer(msg.sender, receiver, amount);
return true;
}
function getBalanceInEth(address addr) public view returns(uint){
return ConvertLib.convert(getBalance(addr),2);
}
function getBalance(address addr) public view returns(uint) {
return balances[addr];
}
}
Есть ли что-то, что я не делаю в правильном направлении? Я не изменил какой-либо предоставленный код. Спасибо!