add a few test files

This commit is contained in:
Tim Williams 2018-04-13 10:04:25 -04:00 committed by greg
parent cfa2588c9d
commit 68b124382a
5 changed files with 71 additions and 0 deletions

4
checkbalances.js Normal file
View file

@ -0,0 +1,4 @@
console.log("Checking balances...")
for(i = 0; i < web3.eth.accounts.length; i++){
console.log(web3.eth.accounts[i] + ":" + web3.eth.getBalance(web3.eth.accounts[i]))
}

27
deployContract.js Normal file
View file

@ -0,0 +1,27 @@
// using contract from https://www.ethereum.org/greeter
// compiled on remix
var _greeting = "Greeter Contract" ;
var greeterContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);
var greeter = greeterContract.new(
_greeting,
{
from: web3.eth.accounts[0],
data: '0x6060604052341561000f57600080fd5b6040516103a93803806103a983398101604052808051820191905050336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060019080519060200190610081929190610088565b505061012d565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100c957805160ff19168380011785556100f7565b828001600101855582156100f7579182015b828111156100f65782518255916020019190600101906100db565b5b5090506101049190610108565b5090565b61012a91905b8082111561012657600081600090555060010161010e565b5090565b90565b61026d8061013c6000396000f30060606040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806341c0e1b514610051578063cfae321714610066575b600080fd5b341561005c57600080fd5b6100646100f4565b005b341561007157600080fd5b610079610185565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b957808201518184015260208101905061009e565b50505050905090810190601f1680156100e65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610183576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b565b61018d61022d565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102235780601f106101f857610100808354040283529160200191610223565b820191906000526020600020905b81548152906001019060200180831161020657829003601f168201915b5050505050905090565b6020604051908101604052806000815250905600a165627a7a7230582015882dcaabcda0ebdb1b26a10e36f26a424e148671f4703dde3c1956ebaa67830029',
gas: '4700000'
}, function (e, contract){
if(!e) {
// NOTE: The callback will fire twice!
// Once the contract has the transactionHash property set and once its deployed on an address.
// e.g. check tx hash on the first call (transaction send)
if(!contract.address) {
console.log("TX hash:")
console.log(contract.transactionHash) // The hash of the transaction, which deploys the contract
} else {
console.log("Contract address:")
console.log(contract.address) // the contract address
}
}
})

7
getGreeting.js Normal file
View file

@ -0,0 +1,7 @@
var abi = [{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]
function getGreeting(address){
var MyContract = web3.eth.contract(abi);
var myContractInstance = MyContract.at(address);
console.log(myContractInstance.greet())
}

4
run_js_in_geth.sh Normal file
View file

@ -0,0 +1,4 @@
file=$1
echo $file
runthing="./build/bin/geth --exec 'loadScript(\""$file"\")' attach http://127.0.0.1:8545"
eval $runthing

29
sendTransactions.js Normal file
View file

@ -0,0 +1,29 @@
var firstAccount = web3.eth.accounts[0]
var secondAccount = web3.eth.accounts[1]
var thirdAccount = web3.eth.accounts[2]
console.log(firstAccount)
web3.eth.sendTransaction({
from: web3.eth.accounts[0],
to: web3.eth.accounts[1],
value: 623,
gas: 50000,
gasPrice: 20
})
web3.eth.sendTransaction({
from: web3.eth.accounts[0],
to: web3.eth.accounts[2],
value: 291,
gas: 50000,
gasPrice: 20
})
web3.eth.sendTransaction({
from: web3.eth.accounts[1],
to: web3.eth.accounts[3],
value: 53039,
gas: 50000,
gasPrice: 20
})