Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
2eedc330
Commit
2eedc330
authored
Jan 30, 2015
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
contract with array example
parent
600c9dd2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
0 deletions
+76
-0
contract_with_array.html
example/contract_with_array.html
+76
-0
No files found.
example/contract_with_array.html
0 → 100644
View file @
2eedc330
<
!
doctype
>
<html>
<head>
<script
type=
"text/javascript"
src=
"js/bignumber.js/bignumber.min.js"
></script>
<script
type=
"text/javascript"
src=
"../dist/ethereum.js"
></script>
<script
type=
"text/javascript"
>
var
web3
=
require
(
'web3'
);
web3
.
setProvider
(
new
web3
.
providers
.
HttpSyncProvider
());
// solidity source code
var
source
=
""
+
"contract test {
\n
"
+
" function multiply(uint[] a) returns(uint d) {
\n
"
+
" return a[0] + a[1];
\n
"
+
" }
\n
"
+
"}
\n
"
;
// contract description, this will be autogenerated somehow
var
desc
=
[{
"name"
:
"multiply(uint256[])"
,
"type"
:
"function"
,
"inputs"
:
[
{
"name"
:
"a"
,
"type"
:
"uint256[]"
}
],
"outputs"
:
[
{
"name"
:
"d"
,
"type"
:
"uint256"
}
]
}];
var
contract
;
function
createExampleContract
()
{
// hide create button
document
.
getElementById
(
'create'
).
style
.
visibility
=
'hidden'
;
document
.
getElementById
(
'source'
).
innerText
=
source
;
// create contract
var
address
=
web3
.
eth
.
transact
({
code
:
web3
.
eth
.
solidity
(
source
)});
contract
=
web3
.
eth
.
contract
(
address
,
desc
);
document
.
getElementById
(
'call'
).
style
.
visibility
=
'visible'
;
}
function
callExampleContract
()
{
// this should be generated by ethereum
var
param
=
parseInt
(
document
.
getElementById
(
'value'
).
value
);
var
param2
=
parseInt
(
document
.
getElementById
(
'value2'
).
value
);
// call the contract
var
res
=
contract
.
call
().
multiply
([
param
,
param2
]);
document
.
getElementById
(
'result'
).
innerText
=
res
.
toString
(
10
);
}
</script>
</head>
<body>
<h1>
contract
</h1>
<div
id=
"source"
></div>
<div
id=
'create'
>
<button
type=
"button"
onClick=
"createExampleContract();"
>
create example contract
</button>
</div>
<div
id=
'call'
style=
'visibility: hidden;'
>
<input
type=
"number"
id=
"value"
onkeyup=
'callExampleContract()'
></input>
<input
type=
"number"
id=
"value2"
onkeyup=
'callExampleContract()'
></input>
</div>
<div
id=
"result"
></div>
</body>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment