I'm Beginner of Ethereum and now test the transaction in My testnet
when I testing the sendtransaction below
eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:web3.toWei(10), chainId: 0})
Return error like this "Error: only replay-protected (EIP-155) transactions allowed over RPC"
How can I modify it?
enter image description here
EIP-155 introduced to include the chainId inside the transaction to avoid replays of the transaction on different chain, check which chainId corresponds to the network you are using and update the chainId value accordingly.
Related
According to the docs for web3.eth.sendTransaction and the docs for eth_sendTransaction:
The transaction object can contain an optional data parameter which should be a String that consists of:
either an ABI byte string containing the data of the function call on a contract, or in the case of a contract-creation transaction the initialisation code.
I want to assign a string to data and have the string be stored along with the record of the transaction on the blockchain, so that I can retrieve that string when I retrieve the record of that transaction later.
const [testAccount] = await window.ethereum.request({ method: "eth_requestAccounts" })
const web3 = new Web3(window.ethereum)
if (!testAccount) {
return
}
let transactionHash = await web3.eth.sendTransaction({
from: testAccount,
to: testAccount,
value: web3.utils.toWei('0.0003'),
data: web3.utils.utf8ToHex(JSON.stringify({ a: 1, b: 2 }))
})
let transaction = await web3.eth.getTransaction(transactionHash)
let data = JSON.parse(web3.utils.hexToUtf8(transaction.data))
console.log(data.a) // should log 1
When I execute sendTransaction (using Metamask, while connected to the Ropsten network), I get the following error:
Error: Error: TxGasUtil - Trying to call a function on a non-contract address
{
"originalError": {
"errorKey": "transactionErrorNoContract",
"getCodeResponse": "0x"
}
}
Apparently, you cannot assign any string to data and expect the string to be incorporated in the record of the transaction on the blockchain, out-of-the-box, simply by assigning a value to it. Is this correct?
Question: Do I need to write a custom smart-contract in order to achieve this ?
This is a feature/limitation specific to MetaMask. Possibly to protect their users who want to interact with a smart contract but are connected to a different network where the contract is not deployed.
However, it is technically possible to send a valid transaction with non-empty data field to a non-contract address. You just need to use a different node provider to broadcast the transaction. Unfortunately the node provider in MetaMask is hardcoded so it's not possible using this wallet.
Example: This transaction on the Ropsten testnet to the 0xdac1... address that has the USDT token contract deployed on the mainnet, but is a non-contract address on the testnet. It is a valid transaction, successfully bought gas from the sender address to cover the transaction fees, mined in a block, just didn't execute any smart contract code (as there is no smart contract on the recipient address).
Do I need to write a custom smart-contract in order to achieve this ?
You can also write a smart contract function in Solidity that receives data as a function argument, but does nothing on this. Thus, GoEthereum node stores this data as calldata of the transaction and it can be later retrieved.
I am pretty sure some cross-chain bridges operate in this manner. Transactions only write data as the part of calldata (cheaper than Solidity storage) and then other clients read it from there.
Using openzeppelin's UUPS upgradeable proxy contracts results in the following slither error. Are they false positives or should I be concerned?
Enviornment:
"#openzeppelin/contracts-upgradeable": "^4.5.2",
$ slither .
'npx hardhat compile --force' running
hardhat solidity version 0.8.9
Error 1:
ERC1967UpgradeUpgradeable._functionDelegateCall(address,bytes) (node_modules/#openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol#198-204) uses delegatecall to a input-controlled function id
- (success,returndata) = target.delegatecall(data) (node_modules/#openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol#202)
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#controlled-delegatecall
Error 2:
ERC1967UpgradeUpgradeable._upgradeToAndCallUUPS(address,bytes,bool).slot (node_modules/#openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol#98) is a local variable never initialized
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#uninitialized-local-variables
Error 3:
ERC1967UpgradeUpgradeable._upgradeToAndCallUUPS(address,bytes,bool) (node_modules/#openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol#87-105) ignores return value by IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() (node_modules/#openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol#98-102)
ERC721Upgradeable._checkOnERC721Received(address,address,uint256,bytes) (node_modules/#openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol#393-414) ignores return value by IERC721ReceiverUpgradeable(to).onERC721Received(_msgSender(),from,tokenId,_data) (node_modules/#openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol#400-410)
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#unused-return
No, slither often flags OpenZepplin contracts, because they often use low-level functions like delegatecall or use assembly to deal with the return data.
So it's fine just keep in mind that while slither is an amazing piece of software it can't detect everything correctly.
I am basically setting up a smart contract where if a second transaction isnt in same block the first transaction should fail.
A long time ago I saw documentation which showed how to get the current state I think it called it.
Which suggested it was possible to get information such as the block ID at the time the transaction was being confirmed.
I do not have any example at the moment as I can't find any information to test which is why I am asking here.
So does anybody know a way for the contract to check if another transaction is in the current block?
Thanks alot for any help.
I am basically setting up a smart contract where if a second transaction isnt in same block the first transaction should fail.
I'm uncertain what exactly it is you're trying to do but I can't imagine this is a secure operation in practice. Ultimately the second transaction will not have any way to guarantee that the first transaction is the one that actually ends up getting mined in that current block (it could be replaced by a replacement/cancel tx, or it could have insufficient gas price and get mined in the next block, etc).
All that being said, you can use the contract state to store persistent data in the contract on-chain, but that state won't be updated until it a 'mined' contract call updates it. In other words, you won't be able to check if a tx is in the same block, but you can check if a tx is in a previous block.
pragma solidity >=0.4.0 <0.9.0;
contract SimpleStorage {
mapping (string => blockNumber) public transactions;
function recordMyTransaction(string memory _id) public {
transactions[_id] = block.number;
}
function executeThingIfTransactionExists(string memory _id) public {
// string comparison
require(transactions[_id] != 0);
// ... do the thing
}
}
See solidity 0.8.7 docs.
Otherwise, you could do something like this using an oracle. But again, no guarantee that the transaction you're looking at is the one that goes through.
I use Ganache, truffle.
I get the following error:
Error: [ethjs-query] while formatting outputs from RPC '{"value":{"code":-32603,"data":{"message":"VM Exception while processing transaction
I have located the problematic piece of code:
bool sent = _sellerAddress.send(_price);
Now, I get the price via the user interaction, and when the price is 0, then the error is not thrown,
unfortunately in the classic case when the _price is no zero, the exception is thrown.
Any suggestions?
I have ERC-20 token smart-contract which methods I call using sendSignedTransaction from web3.js. After I know transaction is succesfully mined I need to check contract method execution result. How do I do it if all I have is transaction hash?
Example: method transferFrom(from, to, tokens) returns true or false depending on whether transferring was successful. So if I try to transfer 100 tokens from empty wallet, contract method will return false.
Upd: Okay, as I understood there is no way of determining method outcome using txHash after transaction is mined and confirmed. Then which ways exists to handle this case? How can I make sure that tokens were transferred?
You can emit an event inside your contract code ( actually in ERC20 standard there is always a transfer event present ) and then inside web3js, read all the events till latest block using this line of code:
Events = Contract.eventName({}, {fromBlock: 0, toBlock: 'latest'});