Created
October 16, 2019 18:12
-
-
Save sebastinez/4ff17e7aa7e943966f5dcbec0d1e58e3 to your computer and use it in GitHub Desktop.
Deployment of RNS Contracts to Ganache
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
async function deployRNS() { | |
try { | |
var web3 = new Web3(); | |
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545")); | |
accounts = await web3.eth.getAccounts(); | |
var input = { | |
"AbstractRNS.sol": fs.readFileSync("./AbstractRNS.sol").toString(), | |
"RNS.sol": fs.readFileSync("./RNS.sol").toString(), | |
"ResolverInterface.sol": fs.readFileSync("./ResolverInterface.sol").toString(), | |
"PublicResolver.sol": fs.readFileSync("./PublicResolver.sol").toString() | |
}; | |
var compiled = solc.compile({ sources: input }, 1); | |
// Deploy the RNS contract | |
var deployer = compiled.contracts["RNS.sol:RNS"]; | |
var deployRNSContract = new web3.eth.Contract(JSON.parse(deployer.interface)); | |
rnsContract = await deployRNSContract | |
.deploy({ | |
data: deployer.bytecode | |
}) | |
.send({ | |
from: accounts[0], | |
gas: 6700000, | |
gasPrice: 1000000 | |
}); | |
// Deploy the PublicResolver contract | |
deployer = compiled.contracts["PublicResolver.sol:PublicResolver"]; | |
var resolverABI = fs.readFileSync("./resolver.json").toString(); | |
var deployResolverContract = new web3.eth.Contract(JSON.parse(resolverABI)); | |
resolverContract = await deployResolverContract | |
.deploy({ | |
data: deployer.bytecode, | |
arguments: [rnsContract._address.toString()] | |
}) | |
.send({ | |
from: accounts[0], | |
gas: 6700000, | |
gasPrice: 1000000 | |
}); | |
return resolverContract.options.address; | |
} catch (e) { | |
throw Error(e); | |
} | |
} | |
deployRNS() | |
.then(resolver => { | |
console.log(resolver); | |
}) | |
.catch(e => { | |
console.log(e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment