In this example:
contract SimpleStorage {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
1. Is the storage variable storedData being stored permanently, or temporarily?
2. If I send this contract data with the JS API (such as below):
web3.eth.transact({ 'to': configAddr, data: [web3.fromAscii('set'), web3.fromAscii(10)]});
How do I access the data stored in storedData?
I've tried stateAt and storageAt to no end (such as below). Cant seem to get this going.
web3.eth.stateAt(configAddr, "0").then(function (result) {
var storage = result;
});
How would I go about using the get function in this contract? Would I use the call function in the JS API?
I'm using POC-8 unstable on Ubuntu x64.
SC.
0 ·
Comments
https://github.com/ethereum/ethereum.js/blob/master/example/contract.html
You also first have to tell the javascript frontend the interface of the Solidity contract you want to call (this is done by web3.contract in the example). After that, you can call solidity functions directly from javascript. If you want to make a real transaction and not just a "local call", use transact() instead of call().
I posted this to the BC (with enough gas):
contract SimpleStorage {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
Retrieved the contract address. Then posted to it with this:
web3.eth.transact({ 'to': CONTRACT_ADDRESS, data: [web3.fromAscii('set'), web3.fromAscii(10)]});
And attempted the stateAt and storageAt functions they returned nothing except maybe a '0x' or '{}'.
I tried the call function as well, no data was in the response.
Any thoughts? I'll update my build tonight and try again, maybe a bug.
web3.contract(CONTRACT_ADDRESS, abiNameReg).set("My Name").transact();
Not:
web3.eth.transact({ 'to': CONTRACT_ADDRESS, data: [web3.fromAscii('set'), web3.fromAscii("My name")]});
Cheers
function depositMoney(){
account[msg.sender].balance += msg.value;
}
And I want to call it like this:
function deposit(){
var amount = document.getElementById('depositAmount').value;
contract.call(amount).deposit();
}
How can I do that? Anyone???
transact
(sendTransaction
with the new API):contract.sendTransaction({value: value}).depositMoney();
contract.sendTransaction({"value": 100}).depositMoney();
But had no luck
I'm pretty sure the contract object is alright, because functions that do not require ether like contract.call().blabla() work.
Can you give me a source where you got your information from so I can check on that? Btw I'm using Alethzero not the Go client. ...Man that stuff is killing me...
https://github.com/ethereum/ethereum.js
https://github.com/ethereum/wiki/wiki/JavaScript-API
I actually use it in my project https://github.com/jorisbontje/sleth