- A compiler that compiles Smart Contract written in Solidity to Javascript - a language that almost developers know and can use quickly.
Just npm start
, open http://localhost:3000 to view it in the browser,
paste your Solidity code in the left area and Hot Dog, the result appears.
Then, you need to manually modify the Generated JavaScript code results to function properly.
- We map
Contract
in Solidity toClass
in Javascript. So we need to usethis pointer
to reference state of class. - The default decorator of class method is
@view
, depends on your code, you may want to change it to@transaction
.
pragma solidity ^0.4.0;
contract SimpleStorage {
uint storedData;
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint) {
return storedData;
}
}
This is a super simple solidity smart contract. Here is the code you would acquire after using the compiler:
//Pragma solidity version ^0.4.0
@contract
class SimpleStorage {
@state
#storedData;
@view
set(x) {
storedData = x;
}
@view
get() {
return storedData;
}
}
- It is clearly seen that there is a state
storedData
, it is referenced byset()
andget()
method down below. So we need to add thethis pointer
:storedData
->this.storedData
- Because the
set()
method change the state of the contract, it should not be decorated with@view
:@view
->@transaction
- Put it all together, we are good to go:
@contract
class SimpleStorage {
@state
#storedData;
@transaction
set(x) {
this.storedData = x;
}
@view
get() {
return this.storedData;
}
}
- contract, interface.
- state property, variable inside function.
- function, state mutability, modifier.
- array.
- common opertator.
- map.
- inheritance.
- more...
- We use solidity-parser-antlr to parse the Solidity code and get the Solidity AST (Abstract Syntax Tree).
- We fork the ASTexplorer website for easy using.