solidity[59]-infura-deploy
infura
在之前,我们使用了本地的ganache-cli测试网络+mocha测试部署交互合约。现在,我们需要使用到infura将合约部署到真实的区块链的网络当中。
我们都知道,如果我们本身不是一个以太坊的节点,那么我们就需要将我们的交易发送给其他的节点来挖矿确认。infura就是默认的维护了许多的节点,我们通过它就能够与以太坊进行连接。
安装模块
1
| npm install --save truffle-hdwallet-provider
|
利用infura部署合约
deploy.js:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3'); const {interface,bytecode} = require('./compile');
const provider = new HDWalletProvider( 'type give repair twenty split notable humor sweet obey pizza click absurd', 'https://ropsten.infura.io/v3/de22b468cb7846788b4d1ae36bcc26c2' );
const web3 = new Web3(provider);
const deploy = async ()=>{ console.log(interface); const accounts = await web3.eth.getAccounts(); const result = await new web3.eth.Contract(JSON.parse(interface)).deploy({data:'0x'+bytecode}) .send({from:accounts[0],gas:'1000000'}); console.log('contract deployed to ',result.options.address);
} deploy();
|
部署
灾难总是接踵而至,这正是世间的常理。你以为只要哭诉一下,就会有谁来救你?如果失败了,就只能说明我不过是如此程度的男人