Last active
April 12, 2019 09:32
-
-
Save leberknecht/250496da11fea1966657084f1069934e to your computer and use it in GitHub Desktop.
Web3 v1.0 deploy contract using truffle-hd-wallet provider
This file contains hidden or 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
/* 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(provider) | |
let HDWalletProvider = require("truffle-hdwallet-provider") | |
let mnemonic = PUT 12 WORDS HERE | |
let provider = new HDWalletProvider(mnemonic, FILL HOST URL HERE - LIKE INFURA) | |
(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: FILL ADDRESS HERE, | |
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