I try to test one of my first Smart Contract in Solidity, a simple sub currency example, as you can see below :
pragma solidity ^0.4.0;
contract Coin {
address public owner;
mapping (address => uint) balances;
function Coin() {
owner = msg.sender;
balances[tx.origin] = 1000;
}
function send(address receiver, uint amount) returns (bool success) {
if (balances[msg.sender] < amount) {
return false;
}
balances[msg.sender] -= amount;
balances[receiver] += amount;
return true;
}
function getBalance (address user) constant returns (uint balance) {
return balances[user];
}
}
After migration and compile, please look my truffle command in the console
> var a = web3.eth.accounts[0]
> var b = web3.eth.accounts[1]
> var coin = Coin.deployed()
> coin.then(function(instance) {return instance.getBalance.call(a);})
{ [String: '1000'] s: 1, e: 3, c: [ 1000 ] }
> coin.then(function(instance) {return instance.getBalance.call(b);})
> { [String: '0'] s: 1, e: 0, c: [ 0 ] }
At this point I'm agree with these output, but when I want to make the transaction, they said I don't have enough funds ...:
> coin.then(function(instance) {return instance.send(b,500);})
Error: Error: sender doesn't have enough funds to send tx. The upfront cost is: 724579920256558730963659928732440307373701337785 and the senders account only has: 99835768400000000000
at runCall (/usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/lib/runTx.js:97:10)
at /usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/node_modules/async/dist/async.js:3686:9
at replenish (/usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/node_modules/async/dist/async.js:882:17)
at iterateeCallback (/usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/node_modules/async/dist/async.js:867:17)
at /usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/node_modules/async/dist/async.js:840:16
at /usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/ethereumjs-vm/node_modules/async/dist/async.js:3691: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.async.eachSeries (/usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/async-eventemitter/node_modules/async/lib/async.js:130:20)
at VM.AsyncEventEmitter.emit (/usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/async-eventemitter/lib/AsyncEventEmitter.js:42:9)
at Object.InvalidResponse (/usr/local/lib/node_modules/truffle/node_modules/truffle-contract/node_modules/web3/lib/web3/errors.js:35:16)
at /usr/local/lib/node_modules/truffle/node_modules/truffle-contract/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:119: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:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
I tried with other accounts available in Testrpc, I've same results ... May be I missed something in my command or set up I Don't know. But this cost seems to important, no ?
Thanks for your help !
balances[owner]
everytime for any address. Is this the same contract you used in your truffle tests?balances[user]
and notbalances[owner]
!