scripts updated

sl
aniket-engg 4 years ago committed by Aniket
parent 8be52cfe02
commit a14b9109b7
  1. 104
      apps/remix-ide/src/app/editor/examples.js

@ -248,64 +248,66 @@ contract BallotTest {
} }
} }
` `
const deployWithWeb3 = `(async () => { const deployWithWeb3 = `// Right click on the script name and hit "Run" to execute
(async () => {
try { try {
console.log('Running deployWithWeb3 script...') console.log('Running deployWithWeb3 script...')
const contractName = 'Storage' // Change this for other contract const contractName = 'Storage' // Change this for other contract
const constructorArgs = [] // Put constructor args (if any) here for your contract const constructorArgs = [] // Put constructor args (if any) here for your contract
// Note that the script needs the ABI which is generated from the compilation artifact. // Note that the script needs the ABI which is generated from the compilation artifact.
// Make sure contract is compiled and artifacts are generated // Make sure contract is compiled and artifacts are generated
const artifactsPath = \`browser/contracts/artifacts/\${contractName}.json\` // Change this for different path const artifactsPath = \`browser/contracts/artifacts/\${contractName}.json\` // Change this for different path
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
const accounts = await web3.eth.getAccounts() const accounts = await web3.eth.getAccounts()
let contract = new web3.eth.Contract(metadata.abi) let contract = new web3.eth.Contract(metadata.abi)
contract = contract.deploy({ contract = contract.deploy({
data: metadata.data.bytecode.object, data: metadata.data.bytecode.object,
arguments: constructorArgs arguments: constructorArgs
}) })
const newContractInstance = await contract.send({ const newContractInstance = await contract.send({
from: accounts[0], from: accounts[0],
gas: 1500000, gas: 1500000,
gasPrice: '30000000000' gasPrice: '30000000000'
}) })
console.log('Contract deployed at address: ', newContractInstance.options.address) console.log('Contract deployed at address: ', newContractInstance.options.address)
} catch (e) { } catch (e) {
console.log(e.message) console.log(e.message)
} }
})()` })()`
const deployWithEthers = `(async function() { const deployWithEthers = `// Right click on the script name and hit "Run" to execute
(async () => {
try { try {
console.log('Running deployWithEthers script...') console.log('Running deployWithEthers script...')
const contractName = 'Storage' // Change this for other contract const contractName = 'Storage' // Change this for other contract
const constructorArgs = [] // Put constructor args (if any) here for your contract const constructorArgs = [] // Put constructor args (if any) here for your contract
// Note that the script needs the ABI which is generated from the compilation artifact. // Note that the script needs the ABI which is generated from the compilation artifact.
// Make sure contract is compiled and artifacts are generated // Make sure contract is compiled and artifacts are generated
const artifactsPath = \`browser/contracts/artifacts/\${contractName}.json\` // Change this for different path const artifactsPath = \`browser/contracts/artifacts/\${contractName}.json\` // Change this for different path
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath))
// 'web3Provider' is a remix global variable object // 'web3Provider' is a remix global variable object
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner() const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner()
let factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer); let factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer);
let contract = await factory.deploy(...constructorArgs); let contract = await factory.deploy(...constructorArgs);
console.log('Contract Address: ', contract.address); console.log('Contract Address: ', contract.address);
// The contract is NOT deployed yet; we must wait until it is mined // The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed() await contract.deployed()
console.log('Deployment successful.') console.log('Deployment successful.')
} catch (e) { } catch (e) {
console.log(e.message) console.log(e.message)
} }
})()` })()`

Loading…
Cancel
Save