You're missing a step. Your result is going to be the unmined transaction receipt. tx.input is the data you sent.
The next step is to wait for the transaction to be mined, and then get the mined transaction with the returned values.
Xavier well-solved example code here: https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6
The "data" you're sending is Hex. "uint data" should probably be "bytes32 data".
tx.origin is security risk. Avoid it unless you really know what you're doing. msg.sender will work.
Instead of returning on insufficient funds, it's almost always better to throw. This is the opposite of other situations where we tend to want to detect errors and then decide what to do.
On success return true indicating the transaction was executed as requested. No need to return values the client already knows. Include "returns" in the function so there is no doubt about what's coming back. I called it "success".
Add event logs to emit state notices about state changes. I added one for send(). There should also be one for mint().
In practice, you'll find that you can often use watchers to listen for LogSent and other events and maintain the UI. Watchers will fire when the mined transactions are detected.
contract Coin {
address public minter;
mapping (address => uint) public balances;
event LogSent(address from, address to, uint amount, bytes32 data);
function Coin() {
balances[msg.sender] = 1000000000000000000000000000000000000;
minter = msg.sender;
}
function mint(address receiver, uint amount) {
if (msg.sender != minter) return;
balances[receiver] += amount;
}
function send(address receiver, uint amount, bytes32 data)
returns(bool success)
{
if (balances[msg.sender] < amount) throw;
balances[msg.sender] -= amount;
balances[receiver] += amount;
LogSent(msg.sender, receiver, amount, data);
return true;
}
}
A watcher looks something like this:
var startWatching = watchSent;
function watchSent(address) {
var meta = Coin.at(address); // address of contract to watch
var watcher = meta.LogSent( {}, {fromBlock: 0}) // Log name, filter, from start
.watch(function(err,sent) {
if(err) {
console.error("Something went wrong with the watcher", err);
} else {
// returned arguments are visible
console.log(sent.args.sent, sent.args.receiver, sent.args.amount, sent.args.data);
}
}
Base 16 is hexadecimal. The variable iPos you're giving to getFirstname is base 10 IE "0"
Hexademical is 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F <-- Sixteen positions.
Demical is 0,1,2,3,4,5,6,7,8,9 <-- Ten positions.
The number zero in Base 16 is 0x0.
Best Answer
BN will not accept decimal point numbers. You can do as follows:
Hope this helps