This is what my working dir looks like:
PS C:\Projects\Eth_Dev\simple> ls
Directory: C:\Projects\Eth_Dev\simple
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 27/02/2019 21:25 contracts
d----- 27/02/2019 21:22 node_modules
d----- 27/02/2019 21:25 test
-a---- 27/02/2019 21:25 691 compile.js
-a---- 27/02/2019 21:29 907 deploy.js
-a---- 27/02/2019 21:22 152654 package-lock.json
-a---- 27/02/2019 21:28 339 package.json
The contents of package.json
:
{
"name": "myContract",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC",
"dependencies": {
"ganache-cli": "^6.2.5",
"mocha": "^5.2.0",
"solc": "^0.4.25",
"truffle-hdwallet-provider": "0.0.3",
"web3": "^1.0.0-beta.35"
}
}
The only other command I had to run in addition to npm install
was npm install --global --production windows-build-tools
The contents of contracts\myContract.sol
pragma solidity ^0.4.17;
contract MyContract {
string public message;
function MyContract(string initialMessage) public {
message = initialMessage;
}
function setMessage(string newMessage) public {
message = newMessage;
}
}
This is a deploy.js script that seems to work.
Running 'node deploy.js' does the deploy to the Rinkeby network
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const {interface, bytecode} = require('./compile');
const provider = new HDWalletProvider(
'your twelve word mnemonic',
'https://rinkeby.infura.io/v3/YOUR_API_KEY'
);
const web3 = new Web3(provider);
const deploy = async () => {
const accounts = await web3.eth.getAccounts();
console.log('Attempting to deploy from account', accounts[0]);
const result = await new web3.eth.Contract(JSON.parse(interface))
.deploy({data:bytecode, arguments:['This is deployed!']})
.send({gas:'1000000', from: accounts[0]});
console.log('Contract deployed to ', result.options.address);
};
deploy();
There is a reference to a compile file. The compile.js looks like this:
const path = require('path'); //builds a path from the current file.
const fs = require('fs');
//Need the solidity compiler
const solc = require('solc');
//__dirname will get the inbox dir path.
//look in the contracts folder and get a path to the Inbox.sol file.
const myContractPath = path.resolve(__dirname,'contracts','myContract.sol');
//Read in the contents of the file. The raw source code.
const source = fs.readFileSync(myContractPath,'utf8');
//console.log(solc.compile(source,1));
//This will export the compiled file. Make it available
//At the moment only interested in the Inbox contract.
module.exports = solc.compile(source,1).contracts[':MyContract'];
And the output:
PS C:\Projects\Eth_Dev\simple> node .\deploy.js
Attempting to deploy from account 0x15ec...B
Contract deployed to 0x5...2DA9269a
Ganache can be configured to mine new blocks on a specific time interval. With this setting enabled you are able to include multiple transactions in a single block.
To enable this functionality in the GUI, access the settings by clicking the gear icon in the top right corner. Choose "Server" settings. From there you will be able to disable auto-mining and set the number of seconds between blocks.
To enable it in ganache-cli
, include the --blockTime [number]
flag when launching the program. [number]
is the number of seconds between blocks.
Best Answer
You can write a solidity contract with one method that receives the addresses and the amounts to transfer, and performs the corresponding transfers.
Then you achieve your objective in a single transaction.
For security reasons I recommend to extend the Ownable contract and use the onlyOwner() modifier:
https://docs.openzeppelin.com/contracts/4.x/api/access#Ownable
:)