Last active
August 6, 2021 12:33
-
-
Save asssis/ab26fa83c1d0c5c0e5d1ee675171e235 to your computer and use it in GitHub Desktop.
solid
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
pragma solidity 0.5.3; | |
contract HelloWorld{ | |
string public text; | |
uint public number; | |
address public userAddress; | |
bool public answer; | |
mapping (address => uint) public hasInteracted; | |
function setText(string memory myText) public { | |
text = myText; | |
setInteracted(); | |
} | |
function setNumber(uint myNumber) public payable{ | |
require(msg.value >= 1 ether, "Insuficiente ETH sent."); | |
number = myNumber; | |
setInteracted(); | |
} | |
function setUserAddress() public { | |
userAddress = msg.sender; | |
setInteracted(); | |
} | |
function setAnswer(bool trueOrFalse) public { | |
answer = trueOrFalse; | |
setInteracted(); | |
} | |
function setInteracted() private { | |
hasInteracted[msg.sender] += 1; | |
} | |
function sendETH(address payable targetAddress) public payable{ | |
targetAddress.transfer(msg.value); | |
} | |
//padrão de saques | |
function withdraw() public { | |
require(balances[msg.sender] > 0, "Insufficient funds."); | |
uint amount = balances[msg.sender]; | |
balances[msg.sender] = 0; | |
msg.sender.transfer(amount); | |
} | |
function sum(uint num1, uint num2) public pure returns(uint) { | |
return num1 + num2; | |
} | |
function sumStored(uint num1) public view returns(uint){ | |
return num1 + number; | |
} | |
} | |
//teste https://remix.ethereum.org/ | |
//funcoes pure são gratis, não altera, nem consulta valores da blockchain | |
//funcoes view ja faz consulta de alguma parametro da blockchain | |
//operaçõe | |
// (*) vezes | |
// (/) divisão | |
// (**) potencia | |
web3.eth.getAccounts(); | |
web3.eth.accounts.create(); | |
web3.eth.accounts.privateKeyToAccount('chave'); | |
web3.eth.personal.newAccount() | |
web3.eth.personal.unlockAccount("0xd2439CD82dCC520D25DF57f09C209de068ad39e9") | |
web3.eth.defaultAccount = '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'; | |
web3.eth.defaultAccount = web3.eth.personal.getAccounts()[1]; | |
let accounts = await web3.eth.getAccounts() | |
--rpcapi "eth,net,web3,personal" | |
função rawTransaction | |
var Tx = require('ethereumjs-tx'); | |
var privateKey = new Buffer('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109','hex') | |
var rawTx = { | |
nonce: '0x00', | |
gasPrice: '0x09184e72a000', | |
gasLimit: '0x2710', | |
to: '0x0000000000000000000000000000000000000000', | |
value: '0x00', | |
data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057' | |
} | |
var tx = new Tx(rawTx); | |
tx.sign(privateKey); | |
var serializedTx = tx.serialize(); | |
//console.log(serializedTx.toString('hex')); | |
//0xf889808609184e72a00082271094000000000000000000000000000000000000000080a47f74657374320000000000000000000000000000000000000000000000000000006000571ca08a8bbf888cfa37bbf0bb965423625641fc956967b81d12e23709cead01446075a01ce999b56a8a88504be365442ea61239198e23d1fce7d00fcfc5cd3b44b7215f | |
web3.eth.sendRawTransaction(serializedTx.toString('hex'), function(err, hash) { | |
if (!err) | |
console.log(hash); // "0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385" | |
}); | |
var addr1 = "xxxxx" | |
var pKey1 = "xxxx" | |
var addr2 = "xxxxx" | |
var rawTx = { | |
nonce: web3.toHex(web3.eth.getTransactionCount(addr1)), | |
to: addr2, | |
gasPrice: web3.toHex(21000000000), | |
gasLimit: web3.toHex(21000), | |
value: web3.toHex(web3.toWei(1, 'ether')), | |
data: "" | |
} | |
var pKey1x = new Buffer(pkey1, 'hex') | |
//console.log(pKey1x); | |
//console.log(pKey1x.toString('hex')); | |
var tx = new EthTx(rawTx); | |
tx.sign(pKey1x); | |
var serializedTx = tx.serialize(); | |
//console.log(serializedTx.toString('hex')); | |
web3.eth.sendRawTransaction(serializedTx.toString('hex'),); | |
//web3.eth.sendRawTransaction(serializedTx.toString('hex'), function(err, hash) { | |
// if (!err) | |
// console.log(hash); // "0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385" | |
//}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment