Skip to content

Instantly share code, notes, and snippets.

@leberknecht
Created August 10, 2018 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leberknecht/383104d68fa355b79046fb98a4273e5c to your computer and use it in GitHub Desktop.
Save leberknecht/383104d68fa355b79046fb98a4273e5c to your computer and use it in GitHub Desktop.
deploy a smart contract with Web3 v1.0
/* contract:
pragma solidity ^0.4.23;
contract A {
uint public x = 42;
function someMethod() public view returns(uint)
{
return x;
}
}
*/
const Web3 = require('web3');
let web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'));
(async() => {
let contract = await new web3.eth.Contract([{"constant":true,"inputs":[],"name":"x","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"someMethod","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]);
contract.deploy({
data: '0x6080604052602a60005534801561001557600080fd5b5060d9806100246000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630c55699c14604e5780638d5a4e59146076575b600080fd5b348015605957600080fd5b506060609e565b6040518082815260200191505060405180910390f35b348015608157600080fd5b50608860a4565b6040518082815260200191505060405180910390f35b60005481565b600080549050905600a165627a7a72305820d6ffc8f5dece0a016c4d76c0f02d9dcedc187971750904609baeaa170175eb6f0029'
}).send({
from: '0x8C80ADb6102F7237A888b3e8Bb5fc25fDAEa88a0',
gas: 4700000,
gasPrice: await web3.eth.getGasPrice()
})
.then((instance) => {
instance.methods.someMethod().call().then(console.log);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment