У меня простой контракт Soality, который может хранить собственные балансы для пользователей, но я не могу запустить функцию передачи.
pragma solidity ^0.4.8;
contract SimpleWallet {
address public owner;
mapping (address => uint) balances;
// Constructor
function SimpleWallet(){
owner = msg.sender;
balances[owner] = 1000;
}
function transfer(address _to, uint _value) returns (bool success){
if (balances[msg.sender] < _value) {
return false;
}
balances[msg.sender] -= _value;
balances[_to] += _value;
return true;
}
function getBalance(address _user) constant returns (uint _balance) {
return balances[_user];
}
}
потом побегу..
x = SimpleWallet.deployed()
a1 = web3.eth.accounts[0]
x.then(i => i.getBalance(a1).then(console.log))
И получить возвращенную ошибку
Error: Error: VM Exception while executing eth_call: invalid JUMP at f05bf9ee42d946231b79045ab38aabe852ea0113d27e047820c05041e8c24734/7be97c83604dc80e217456e9da80bc0a2d73f847:43
at /usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/web3-provider-engine/subproviders/vm.js:117:17
at /usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/lib/runTx.js:59:5
at /usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/node_modules/async/dist/async.js:3824:9
at /usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/node_modules/async/dist/async.js:460:16
at replenish (/usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/node_modules/async/dist/async.js:977:25)
at iterateeCallback (/usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/node_modules/async/dist/async.js:967:17)
at /usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/node_modules/async/dist/async.js:944:16
at /usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/node_modules/async/dist/async.js:3821:13
at apply (/usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/node_modules/async/dist/async.js:21:25)
at /usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/node_modules/async/dist/async.js:56:12
at Object.module.exports.InvalidResponse (/usr/local/lib/node_modules/truffle/node_modules/web3/lib/web3/errors.js:35:16)
at /usr/local/lib/node_modules/truffle/node_modules/web3/lib/web3/requestmanager.js:86:36
at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/node_modules/web3/lib/web3/httpprovider.js:118:13)
at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:509:12)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:469:24)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:975:12)
Вот как вы можете получить доступ/вызвать функцию в консоли трюфеля.
$ truffle console
truffle(development)> compile
truffle(development)> contract_name.new('Constructor Initialization')
// Above command will return lot of things on console, second last
// attribute would be address(hash of the contract)
// use it the next line of command
truffle(development)> contract_name.at("contract address").functionName()
Надеюсь это поможет.
После развертывания с помощью трюфеля,
x = SimpleWallet.deployed()
затем вы можете вызывать функции,
var balance =x.getBalance(a)
Просто откройте консоль Truffle с помощью данной команды:$truffle console
и сделать экземпляр контракта
var instance_name = ContractName.at(Contract_Address)
Доступ к Contract_Address можно получить, просто написав: ContractName.address
Когда экземпляр создан, используйте его для вызова функций в смарт-контракте, например:
instance_name.function_name(...)
Бадр Беллай