Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
How secure are blockchain transactions?

I'm developing a DApp project with React, Web3 and solidity to study and I saw that the functions of sending eth to another wallet, within the smart contract, receive a msg.sender, msg.value and a parameter with the address of the recipient. Below I leave my code that I have for now:

<Send.sol>

    pragma solidity ^0.8.10;

    contract Send {
        constructor() payable {}

        receive() external payable {}

        function sendViaCall(address payable _to) external payable {
            (bool success, ) = _to.call{value: msg.value}("");

            require(success, "Send failed");
        }
    }

    contract Receive {
        event Log(uint256 amount, uint256 gas);

        receive() external payable {
            emit Log(msg.value, gasleft());
        }
    }

<withETH.js> (A context for Web3)

    import { createContext, useState, useEffect } from "react";
import { SEND_ABI, SEND_ADDRESS } from "../configs/configContract";
import Web3 from "web3";

export const ETHContext = createContext({
  blockNr: null,
  accountId: null,
  send: () => null,
});

export const ETHProvider = ({ children }) => {
  const [blockNr, setBlockNr] = useState();
  const [accountId, setAccountId] = useState();
  const [contract, setContract] = useState();

  useEffect(() => {
    loadBlockchainData();
  }, []);

  const loadBlockchainData = async () => {
    const web3 = new Web3(Web3.givenProvider || "http://localhost:7545");

    const accounts = await web3.eth.getAccounts();
    setAccountId(accounts[0]);

    const blockNumber = await web3.eth.getBlockNumber();
    setBlockNr(blockNumber);

    const contract = new web3.eth.Contract(SEND_ABI, SEND_ADDRESS);
    setContract(contract);
  };

  const send = async (userId) => {
    const web3 = new Web3(Web3.givenProvider || "http://localhost:7545");

    await contract.methods.sendViaCall(userId).send({
      from: accountId,
      to: userId,
      value: web3.utils.toWei("2", "ether"),
    });
    loadBlockchainData();
  };

  return (
    <ETHContext.Provider
      value={{
        accountId,
        blockNr,
        send,
      }}
    >
      {children}
    </ETHContext.Provider>
  );
};

In the code snippet below, I call my contract template and pass the id of who will receive it, who is being sent (from), who will receive it (to "I imagine this parameter is unnecessary as I go through the parameter of the called function. Am I right?"), and the value (value). What guarantees me that someone will not change the value, the receiver id or their own id?

await contract.methods.sendViaCall(userId).send({
  from: accountId,
  to: userId,
  value: web3.utils.toWei("2", "ether"),
})
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda