Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
compile solidity from your aion node
/*
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))
})
@tcrowe

This comment has been minimized.

Copy link
Owner Author

commented Oct 9, 2018

Also try looking for aion solc aion/aion_fastvm/modFastVM/native/linux/solidity/solc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.