GetBlock() with more parameter

Hi,

I would like to fetch only 1 transaction of a given block.

So these are works:
chain: “bsc”,
block_number_or_hash: Block,

  • And i want to add also “hash”

I can’t use the gettransaction() somehow only the log part (i must to wirte .log behind - otherwise i got error message), but i need all, so that is why i would like to do it with GetBlock()

How can i do that?

Each block will contain one or more transactions. Which is that 1 transaction you are looking for?

Can you share more details on the error which you received while using getTransaction()?

With .log is works perfectly, but without not.
I want the addresses + log array as well

Unhandled Runtime Error
TypeError: transactions2.map is not a function

Source
components\Nft.js (45:44) @ Nft

43 |
44 |

45 | {transactions2 && transactions2.map((transaction2, index) =>
| ^
46 |
47 |
48 | {transaction2.log_index}

Try it this way. It logs total transaction object and also the to_address of each transaction.

const options = {
  chain: "bsc",
  address: "0x3d6c0e79a1239df0039ec16Cc80f7A343b6C530e",
  order: "desc",
  from_block: "0",
};
const transactions = await Moralis.Web3API.account.getTransactions(options); console.log(transactions); 

if (transactions.result.length > 0) {
  transactions.result.forEach((element) => {
    console.log(element.to_address)
    }
  );
}

Hope this relates to something you are looking for.

Thanks, but mine also works with console.log, (when i remove the table object), but when i try to show it in the table then not anymore.

Could you please show me an example of the return in table?

This is what i’m using

        const fetchTransactions2 = async () => {
          const data2 = await Web3Api.native.getTransaction({
            chain: "bsc",
            transaction_hash: Wallet2
           });
            if (data2) {
              setTransactions2(data2);
              console.log(data2)
            }
         };    

        useEffect(() => {
            fetchTransactions2()
        }, [])
    
      return (

      );

do you have a function that returns the table?

I’m testing it on this. It’s works only with (data2.log) but not with (data2)
Of course when i change it, then i delete the <tr></tr> part

      return (
        <TableContainer>
        <Table variant="simple">
          <TableCaption>TRANSACTIONS</TableCaption>
          <Thead>
            <Tr>
              <Th>NONCE</Th>
              <Th>NONCE</Th>                
              <Th>NONCE</Th>
              <Th>NONCE</Th>
            </Tr>
          </Thead>
          <Tbody>

          {transactions2 && transactions2.map((transaction2, index) =>

              <Tr key={transaction2.transaction_hash}>
                  <Th>{transaction2.log_index}</Th>
                  <Th>{transaction2.address}</Th>
                  <Th>{transaction2.topic1}</Th>
                  <Th>{transaction2.topic2}</Th>
                  <Th>{parseInt(transaction2.data, 16)}</Th>
              </Tr>
              
          )}
          </Tbody>
        </Table>
        </TableContainer>
      );
} 

You are getting this error because you are trying to map over an object not an array.

const [transaction, setTransaction] = useState()
    const fetchTransactions2 = async () => {
          const data = await Web3Api.native.getTransaction({
            chain: "bsc",
            transaction_hash: Wallet2
           });
            if (data) {
             setAddressLogs(data.result);
              console.log(data)
            }
         };    

        useEffect(() => {
            fetchTransactions2()
        }, [])
 return (
        <TableContainer>
        <Table variant="simple">
          <TableCaption>TRANSACTIONS</TableCaption>
          <Thead>
            <Tr>
              <Th>NONCE</Th>
              <Th>NONCE</Th>                
              <Th>NONCE</Th>
              <Th>NONCE</Th>
            </Tr>
          </Thead>
          <Tbody>

          {transaction && transaction[logs].map((transaction, index) =>

              <Tr key={transaction.transaction_hash}>
                  <Th>{transaction.log_index}</Th>
                  <Th>{transaction.address}</Th>
                  <Th>{transaction.topic1}</Th>
                  <Th>{transaction.topic2}</Th>
                  <Th>{parseInt(transaction.data, 16)}</Th>
              </Tr>
              
          )}
          </Tbody>
        </Table>
        </TableContainer>
      );


//hope this help

I’ve got now this:

Unhandled Runtime Error
ReferenceError: log is not defined

Source
components\Nft.js (45:42) @ Nft

  43 |           <Tbody>
  44 | 
> 45 |           {transactions2 && transactions2[log].map((transaction2, index) =>
     |                                          ^
  46 | 
  47 |               <Tr key={transaction2.transaction_hash}>
  48 |                   <Th>{transaction2.log_index}</Th>
transactions2 && transactions2[logs]

if you check the doc the transaction has logs property not log https://docs.moralis.io/moralis-dapp/web3-sdk/native