Created
October 9, 2018 21:26
-
-
Save tcrowe/07c64aa6fe29bd3c7b8157e2c731ac5e to your computer and use it in GitHub Desktop.
compile solidity from your aion node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Example how to: | |
+ add RPC calls into Aion Web3 | |
+ check which languages the node can compile | |
+ compile a solidity contract | |
+ inspect results | |
💪🏼 | |
*/ | |
const fs = require("fs") | |
const path = required("path") | |
const Web3 = require("aion-web3") | |
const client = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:8545")) | |
const contractPath = path.join(__dirname, "contracts", "MyContract.sol") | |
// | |
// extend web3.eth object | |
// https://web3js.readthedocs.io/en/1.0/web3.html#extend | |
// | |
client.eth.extend({ | |
methods: [ | |
{ | |
name: "getCompilers", | |
call: "eth_getCompilers" | |
}, | |
{ | |
name: "compileSolidity", | |
call: "eth_compileSolidity", | |
params: 1 | |
} | |
] | |
}) | |
// | |
// see which compilers the node has | |
// | |
client.eth | |
.getCompilers() | |
.then(res => { | |
// res is probably ["solidity"] | |
// res.should.be.an.Array | |
// res.indexOf('solidity').should.not.be.exactly(-1) | |
}) | |
.catch(err => console.error("getCompilers error", err)) | |
// | |
// 1. read a file to a buffer | |
// 2. convert to string | |
// 3. send to aion node via RPC call | |
// 4. inspect result | |
// | |
fs.readFile(contractPath, (err, res) => { | |
if (err !== null && err !== undefined) { | |
console.error('error reading', typesSolPath, err) | |
return done(err) | |
} | |
const source = res.toString() | |
client.eth | |
.compileSolidity(source) | |
.then(res => { | |
// console.log("compileSolidity res", res) | |
const { code, abiDefinition } = res | |
// code is probably the binary, check it | |
// code.should.be.a.String | |
// abi used for contract definition "jsonInterface" | |
// https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html | |
// abiDefinition.should.be.an.Object | |
}) | |
.catch(err => console.error("compileSolidity error", err)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also try looking for aion solc
aion/aion_fastvm/modFastVM/native/linux/solidity/solc