Skip to content

Instantly share code, notes, and snippets.

@harrywang
Created January 31, 2018 16:19
Show Gist options
  • Save harrywang/57fc7169bda18438d54407570d44ed63 to your computer and use it in GitHub Desktop.
Save harrywang/57fc7169bda18438d54407570d44ed63 to your computer and use it in GitHub Desktop.
console interactions
> contractInstance = VotingContract.at(deployedContract.address)
Contract {
_eth:
Eth {
_requestManager: RequestManager { provider: [HttpProvider], polls: {}, timeout: null },
getBalance: { [Function: send] request: [Function: bound ], call: 'eth_getBalance' },
getStorageAt: { [Function: send] request: [Function: bound ], call: 'eth_getStorageAt' },
getCode: { [Function: send] request: [Function: bound ], call: 'eth_getCode' },
getBlock: { [Function: send] request: [Function: bound ], call: [Function: blockCall] },
getUncle: { [Function: send] request: [Function: bound ], call: [Function: uncleCall] },
getCompilers: { [Function: send] request: [Function: bound ], call: 'eth_getCompilers' },
getBlockTransactionCount:
{ [Function: send]
request: [Function: bound ],
call: [Function: getBlockTransactionCountCall] },
getBlockUncleCount:
{ [Function: send]
request: [Function: bound ],
call: [Function: uncleCountCall] },
getTransaction:
{ [Function: send]
request: [Function: bound ],
call: 'eth_getTransactionByHash' },
getTransactionFromBlock:
{ [Function: send]
request: [Function: bound ],
call: [Function: transactionFromBlockCall] },
getTransactionReceipt:
{ [Function: send]
request: [Function: bound ],
call: 'eth_getTransactionReceipt' },
getTransactionCount: { [Function: send] request: [Function: bound ], call: 'eth_getTransactionCount' },
call: { [Function: send] request: [Function: bound ], call: 'eth_call' },
estimateGas: { [Function: send] request: [Function: bound ], call: 'eth_estimateGas' },
sendRawTransaction: { [Function: send] request: [Function: bound ], call: 'eth_sendRawTransaction' },
signTransaction: { [Function: send] request: [Function: bound ], call: 'eth_signTransaction' },
sendTransaction: { [Function: send] request: [Function: bound ], call: 'eth_sendTransaction' },
sign: { [Function: send] request: [Function: bound ], call: 'eth_sign' },
compile: { solidity: [Function], lll: [Function], serpent: [Function] },
submitWork: { [Function: send] request: [Function: bound ], call: 'eth_submitWork' },
getWork: { [Function: send] request: [Function: bound ], call: 'eth_getWork' },
coinbase: [Getter],
getCoinbase: { [Function: get] request: [Function: bound ] },
mining: [Getter],
getMining: { [Function: get] request: [Function: bound ] },
hashrate: [Getter],
getHashrate: { [Function: get] request: [Function: bound ] },
syncing: [Getter],
getSyncing: { [Function: get] request: [Function: bound ] },
gasPrice: [Getter],
getGasPrice: { [Function: get] request: [Function: bound ] },
accounts: [Getter],
getAccounts: { [Function: get] request: [Function: bound ] },
blockNumber: [Getter],
getBlockNumber: { [Function: get] request: [Function: bound ] },
protocolVersion: [Getter],
getProtocolVersion: { [Function: get] request: [Function: bound ] },
iban:
{ [Function: Iban]
fromAddress: [Function],
fromBban: [Function],
createIndirect: [Function],
isValid: [Function] },
sendIBANTransaction: [Function: bound transfer] },
transactionHash: null,
address: '0xd52623be01e3fb1d8a233d6986cea5b25f83b31b',
abi:
[ { constant: true,
inputs: [Array],
name: 'totalVotesFor',
outputs: [Array],
payable: false,
stateMutability: 'view',
type: 'function' },
{ constant: true,
inputs: [Array],
name: 'validCandidate',
outputs: [Array],
payable: false,
stateMutability: 'view',
type: 'function' },
{ constant: true,
inputs: [Array],
name: 'votesReceived',
outputs: [Array],
payable: false,
stateMutability: 'view',
type: 'function' },
{ constant: true,
inputs: [Array],
name: 'candidateList',
outputs: [Array],
payable: false,
stateMutability: 'view',
type: 'function' },
{ constant: false,
inputs: [Array],
name: 'voteForCandidate',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function' },
{ inputs: [Array],
payable: false,
stateMutability: 'nonpayable',
type: 'constructor' } ],
totalVotesFor:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
bytes32: [Circular] },
validCandidate:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
bytes32: [Circular] },
votesReceived:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
bytes32: [Circular] },
candidateList:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
uint256: [Circular] },
voteForCandidate:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
bytes32: [Circular] },
allEvents: [Function: bound ] }
> contractInstance = VotingContract.at(deployedContract.address)
Contract {
_eth:
Eth {
_requestManager: RequestManager { provider: [HttpProvider], polls: {}, timeout: null },
getBalance: { [Function: send] request: [Function: bound ], call: 'eth_getBalance' },
getStorageAt: { [Function: send] request: [Function: bound ], call: 'eth_getStorageAt' },
getCode: { [Function: send] request: [Function: bound ], call: 'eth_getCode' },
getBlock: { [Function: send] request: [Function: bound ], call: [Function: blockCall] },
getUncle: { [Function: send] request: [Function: bound ], call: [Function: uncleCall] },
getCompilers: { [Function: send] request: [Function: bound ], call: 'eth_getCompilers' },
getBlockTransactionCount:
{ [Function: send]
request: [Function: bound ],
call: [Function: getBlockTransactionCountCall] },
getBlockUncleCount:
{ [Function: send]
request: [Function: bound ],
call: [Function: uncleCountCall] },
getTransaction:
{ [Function: send]
request: [Function: bound ],
call: 'eth_getTransactionByHash' },
getTransactionFromBlock:
{ [Function: send]
request: [Function: bound ],
call: [Function: transactionFromBlockCall] },
getTransactionReceipt:
{ [Function: send]
request: [Function: bound ],
call: 'eth_getTransactionReceipt' },
getTransactionCount: { [Function: send] request: [Function: bound ], call: 'eth_getTransactionCount' },
call: { [Function: send] request: [Function: bound ], call: 'eth_call' },
estimateGas: { [Function: send] request: [Function: bound ], call: 'eth_estimateGas' },
sendRawTransaction: { [Function: send] request: [Function: bound ], call: 'eth_sendRawTransaction' },
signTransaction: { [Function: send] request: [Function: bound ], call: 'eth_signTransaction' },
sendTransaction: { [Function: send] request: [Function: bound ], call: 'eth_sendTransaction' },
sign: { [Function: send] request: [Function: bound ], call: 'eth_sign' },
compile: { solidity: [Function], lll: [Function], serpent: [Function] },
submitWork: { [Function: send] request: [Function: bound ], call: 'eth_submitWork' },
getWork: { [Function: send] request: [Function: bound ], call: 'eth_getWork' },
coinbase: [Getter],
getCoinbase: { [Function: get] request: [Function: bound ] },
mining: [Getter],
getMining: { [Function: get] request: [Function: bound ] },
hashrate: [Getter],
getHashrate: { [Function: get] request: [Function: bound ] },
syncing: [Getter],
getSyncing: { [Function: get] request: [Function: bound ] },
gasPrice: [Getter],
getGasPrice: { [Function: get] request: [Function: bound ] },
accounts: [Getter],
getAccounts: { [Function: get] request: [Function: bound ] },
blockNumber: [Getter],
getBlockNumber: { [Function: get] request: [Function: bound ] },
protocolVersion: [Getter],
getProtocolVersion: { [Function: get] request: [Function: bound ] },
iban:
{ [Function: Iban]
fromAddress: [Function],
fromBban: [Function],
createIndirect: [Function],
isValid: [Function] },
sendIBANTransaction: [Function: bound transfer] },
transactionHash: null,
address: '0xd52623be01e3fb1d8a233d6986cea5b25f83b31b',
abi:
[ { constant: true,
inputs: [Array],
name: 'totalVotesFor',
outputs: [Array],
payable: false,
stateMutability: 'view',
type: 'function' },
{ constant: true,
inputs: [Array],
name: 'validCandidate',
outputs: [Array],
payable: false,
stateMutability: 'view',
type: 'function' },
{ constant: true,
inputs: [Array],
name: 'votesReceived',
outputs: [Array],
payable: false,
stateMutability: 'view',
type: 'function' },
{ constant: true,
inputs: [Array],
name: 'candidateList',
outputs: [Array],
payable: false,
stateMutability: 'view',
type: 'function' },
{ constant: false,
inputs: [Array],
name: 'voteForCandidate',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function' },
{ inputs: [Array],
payable: false,
stateMutability: 'nonpayable',
type: 'constructor' } ],
totalVotesFor:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
bytes32: [Circular] },
validCandidate:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
bytes32: [Circular] },
votesReceived:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
bytes32: [Circular] },
candidateList:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
uint256: [Circular] },
voteForCandidate:
{ [Function: bound ]
request: [Function: bound ],
call: [Function: bound ],
sendTransaction: [Function: bound ],
estimateGas: [Function: bound ],
getData: [Function: bound ],
bytes32: [Circular] },
allEvents: [Function: bound ] }
> contractInstance.totalVotesFor.call('Rama')
BigNumber { s: 1, e: 0, c: [ 0 ] }
> contractInstance.totalVotesFor.call('Rama').toNumber()
0
> contractInstance.voteForCandidate('Rama', {from: web3.eth.accounts[0]})
'0xc38a18031b7a14382c7a2651c84c10395a73ecad6e36ed2a4d0fe6b4f1a90ef8'
> contractInstance.voteForCandidate('Rama', {from: web3.eth.accounts[0]})
'0x52c84ac3477a15be8737e6f7bb251eb50ecf54d1a916f00c661f2c64521e87ba'
> contractInstance.voteForCandidate('Harry', {from: web3.eth.accounts[0]})
Error: VM Exception while processing transaction: revert
at Object.InvalidResponse (/Users/harrywang/Documents/sandbox/eth-voting/node_modules/web3/lib/web3/errors.js:38:16)
at RequestManager.send (/Users/harrywang/Documents/sandbox/eth-voting/node_modules/web3/lib/web3/requestmanager.js:61:22)
at Eth.send [as sendTransaction] (/Users/harrywang/Documents/sandbox/eth-voting/node_modules/web3/lib/web3/method.js:145:58)
at SolidityFunction.sendTransaction (/Users/harrywang/Documents/sandbox/eth-voting/node_modules/web3/lib/web3/function.js:170:26)
at SolidityFunction.execute (/Users/harrywang/Documents/sandbox/eth-voting/node_modules/web3/lib/web3/function.js:256:37)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment