From c53f277c634143b401d807227ba1ce49d945124a Mon Sep 17 00:00:00 2001 From: Jason-Wanxt Date: Tue, 17 Oct 2023 00:40:26 +0800 Subject: [PATCH 01/21] add customize event --- .../how-tos/customize-precompile.mdx | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/arbitrum-docs/launch-orbit-chain/how-tos/customize-precompile.mdx b/arbitrum-docs/launch-orbit-chain/how-tos/customize-precompile.mdx index 181394a33..907a5e491 100644 --- a/arbitrum-docs/launch-orbit-chain/how-tos/customize-precompile.mdx +++ b/arbitrum-docs/launch-orbit-chain/how-tos/customize-precompile.mdx @@ -162,6 +162,107 @@ You should see something like this: hi ``` +## Option 3: Define a new event + +Here we will still use the precompile `Arbsys` as an example add a simple `Hi` event to be emitted in `SayHi` which we added in Option 1, first go to the [precompiles implementation][precompile_impl_dir_link] directory, and find `ArbSys.go`: + +```go +// ArbSys provides system-level functionality for interacting with L1 and understanding the call stack. +type ArbSys struct { + Address addr // 0x64 + L2ToL1Tx func(ctx, mech, addr, addr, huge, huge, huge, huge, huge, huge, []byte) error + L2ToL1TxGasCost func(addr, addr, huge, huge, huge, huge, huge, huge, []byte) (uint64, error) + SendMerkleUpdate func(ctx, mech, huge, bytes32, huge) error + SendMerkleUpdateGasCost func(huge, bytes32, huge) (uint64, error) + InvalidBlockNumberError func(huge, huge) error + + // Add your customize event here: + Hi func(ctx, mech, addr) error + // This is needed which will tell you how much gas it will cost, the param is the same as your event but without the first two (ctx, mech), the return param is always (uint64, error) + HiGasCost func(addr) (uint64, error) + + // deprecated event + L2ToL1Transaction func(ctx, mech, addr, addr, huge, huge, huge, huge, huge, huge, huge, []byte) error + L2ToL1TransactionGasCost func(addr, addr, huge, huge, huge, huge, huge, huge, huge, []byte) (uint64, error) +} +``` + +Then add the event to `SayHi` method: + +```go +func (con *ArbSys) SayHi(c ctx, evm mech) (string, error) { + err := con.Hi(c, evm, c.caller) + return "hi", err +} +``` + +Navigate to the [precompiles interface][precompile_interface_dir_link] directory, open `Arbsys.sol`, and add the required interface. Ensure that the Event name on the interface matches the name of the function you introduced in the previous step: + +```solidity +event Hi(address caller); +``` + +If you want to make the param in event as `index`, just add index to solidity interface as this: + +```solidity +event Hi(address indexed caller); +``` + +Now as emiting events need to cost gas, so we should remove `view` function behavior: + +```solidity +function sayHi() external returns(string memory); +``` + +Next, build Nitro by following the instructions in [How to build Nitro locally](/node-running/how-tos/build-nitro-locally). Note that if you've already built the Docker image, you still need run the last step to rebuild. + +Run Nitro with the following command: + +```shell +docker run --rm -it -v /some/local/dir/arbitrum:/home/user/.arbitrum -p 0.0.0.0:8547:8547 -p 0.0.0.0:8548:8548 @latestNitroNodeImage@ --parent-chain.connection.url= --chain.id= --http.api=net,web3,eth,debug --http.corsdomain=* --http.addr=0.0.0.0 --http.vhosts=* +``` + +:::info + +Note that the instructions provided in [How to run a full node](/node-running/how-tos/running-a-full-node) **will not** work with your Orbit node. See [Command-line options (Orbit)](/launch-orbit-chain/reference/command-line-options) for Orbit-specific CLI flags. + +::: + +### Send the tx and get tx receipt + +Send transaction to `ArbSys`, note as the function is not view/pure function, we need to send transaction with gas cost. +``` +cast send 0x0000000000000000000000000000000000000064 "sayHi()(string)" +``` +Then we will have a transaction hash result, send eth_getTransactionReceipt, you may get: + +``` +{"jsonrpc":"2.0","id":1,"result":{"blockHash":"Your_blockHash","blockNumber":"Your_blockNumber","contractAddress":null,"cumulativeGasUsed":"0x680b","effectiveGasPrice":"0x5f5e100","from":"Your_address","gasUsed":"0x680b","gasUsedForL1":"0xe35","l1BlockNumber":"l1_blockNumber","logs":[{"address":"0x0000000000000000000000000000000000000064","topics":["0xa9378d5bd800fae4d5b8d4c6712b2b64e8ecc86fdc831cb51944000fc7c8ecfa","0x000000000000000000000000{Your_address}"],"data":"0x","blockNumber":"Your_blockNumber","transactionHash":"Your_txHash","transactionIndex":"0x1","blockHash":"Your_blockHash","logIndex":"0x0","removed":false}],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000100000000000000040000000000000080004000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000004000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000","status":"0x1","to":"0x0000000000000000000000000000000000000064","transactionHash":"0xb041f2cd839100bbb449cb6bed3489807649dbb470db9532d6a1cb6d84e4ce93","transactionIndex":"0x1","type":"0x2"}} +``` + +You should see something within the transaction receipt like this: + +``` +"logs":[ + { + "address":"0x0000000000000000000000000000000000000064", + "topics":[ + "0xa9378d5bd800fae4d5b8d4c6712b2b64e8ecc86fdc831cb51944000fc7c8ecfa", + "0x000000000000000000000000{Your_address}" + ], + "data":"0x", + "blockNumber":"0x40", + "transactionHash":"{Your_txHash}", + "transactionIndex":"0x1", + "blockHash":"0x0b367d705002b3575db99354a0964c033f929f26f4442ed347e47ae43a8f28e4", + "logIndex":"0x0", + "removed":false + } + ] +``` +From the `logs` field, we can see the topics[0] `0xa937..cfa`, which is the event encode of `Hi(address)`, you can check it using [4 byte directory](https://www.4byte.directory/event-signatures/?bytes_signature=0xa9378d5bd800fae4d5b8d4c6712b2b64e8ecc86fdc831cb51944000fc7c8ecfa), and topics[1] is `Your_address`. + + From d5c9dc57af338d6997c4f32d7e987a9c27448215 Mon Sep 17 00:00:00 2001 From: Jason-Wanxt Date: Tue, 17 Oct 2023 00:53:12 +0800 Subject: [PATCH 04/21] reorder --- .../launch-orbit-chain/how-tos/customize-precompile.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arbitrum-docs/launch-orbit-chain/how-tos/customize-precompile.mdx b/arbitrum-docs/launch-orbit-chain/how-tos/customize-precompile.mdx index 1309f8900..7f3962682 100644 --- a/arbitrum-docs/launch-orbit-chain/how-tos/customize-precompile.mdx +++ b/arbitrum-docs/launch-orbit-chain/how-tos/customize-precompile.mdx @@ -177,14 +177,14 @@ type ArbSys struct { SendMerkleUpdateGasCost func(huge, bytes32, huge) (uint64, error) InvalidBlockNumberError func(huge, huge) error + // deprecated event + L2ToL1Transaction func(ctx, mech, addr, addr, huge, huge, huge, huge, huge, huge, huge, []byte) error + L2ToL1TransactionGasCost func(addr, addr, huge, huge, huge, huge, huge, huge, huge, []byte) (uint64, error) + // Add your customize event here: Hi func(ctx, mech, addr) error // This is needed which will tell you how much gas it will cost, the param is the same as your event but without the first two (ctx, mech), the return param is always (uint64, error) HiGasCost func(addr) (uint64, error) - - // deprecated event - L2ToL1Transaction func(ctx, mech, addr, addr, huge, huge, huge, huge, huge, huge, huge, []byte) error - L2ToL1TransactionGasCost func(addr, addr, huge, huge, huge, huge, huge, huge, huge, []byte) (uint64, error) } ``` From 598e21223f63652b680a139fce02c274ec6e129e Mon Sep 17 00:00:00 2001 From: Jason-Wanxt Date: Tue, 17 Oct 2023 00:55:55 +0800 Subject: [PATCH 05/21] format --- .../for-devs/third-party-docs/PARSIQ/parsiq.md | 11 +++++------ .../how-tos/customize-precompile.mdx | 3 +-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/arbitrum-docs/for-devs/third-party-docs/PARSIQ/parsiq.md b/arbitrum-docs/for-devs/third-party-docs/PARSIQ/parsiq.md index cbf932c03..ff0637670 100644 --- a/arbitrum-docs/for-devs/third-party-docs/PARSIQ/parsiq.md +++ b/arbitrum-docs/for-devs/third-party-docs/PARSIQ/parsiq.md @@ -1,12 +1,11 @@ --- -title: "Quickstart: PARSIQ (blockchain data API & SDK)" -description: "Learn how to use PARSIQ API and SDK to get Arbitrum data" +title: 'Quickstart: PARSIQ (blockchain data API & SDK)' +description: 'Learn how to use PARSIQ API and SDK to get Arbitrum data' author: Ivan-Ivanitskiy sme: Ivan-Ivanitskiy -sidebar_label: "PARSIQ" +sidebar_label: 'PARSIQ' --- - **[PARSIQ](https://www.parsiq.net/)** is a reliable, fully customizable blockchain data indexer, helping developers to seamlessly access, process and utilize Web3 data - both raw and custom. PARSIQ API allows querying blockchain data such as transactions, token transfers, events, internal function calls, blocks, etc. @@ -19,6 +18,7 @@ to get started. ## PARSIQ Tsunami API PARSIQ Tsunami API is a highly efficient API to fetch raw Web3 data: + - Events, calls, transactions (internal included), transfers, contracts, blocks - you name it. Possibility to use unlimited blockrange makes Tsunami a hard-to-beat solution for realiably getting large amounts of data from the blockchain. CSV Export is available. - Get decoded, human readable data right out of the box. - Need an up to date feeds of data streamed to you in real time? Give our low latency Real Time Streaming service a try. @@ -31,11 +31,10 @@ Please check out our [PARSIQ API Reference](https://docs.parsiq.net/r ## PARSIQ SDK -Some more complicated cases where custom data needs to be stored, accumulated, and calculated, cannot be covered by an API. In that cases, use PARSIQ SDK or go for a Custom Data Lake. They allow you to set up data bases and data processing logic to solve your specific use case. +Some more complicated cases where custom data needs to be stored, accumulated, and calculated, cannot be covered by an API. In that cases, use PARSIQ SDK or go for a Custom Data Lake. They allow you to set up data bases and data processing logic to solve your specific use case. :::info SDK Documentation Please see [PARSIQ SDK documentation](https://docs.parsiq.net/reference/your-own-web3-api) for more details. ::: - diff --git a/arbitrum-docs/launch-orbit-chain/how-tos/customize-precompile.mdx b/arbitrum-docs/launch-orbit-chain/how-tos/customize-precompile.mdx index 7f3962682..32828f69f 100644 --- a/arbitrum-docs/launch-orbit-chain/how-tos/customize-precompile.mdx +++ b/arbitrum-docs/launch-orbit-chain/how-tos/customize-precompile.mdx @@ -231,7 +231,7 @@ Note that the instructions provided in [How to run a full node](/node-running/ho ### Send the transaction and get the transaction receipt -Send transaction to `ArbSys`, note as the function is not view/pure function, we need to send transaction with gas cost. +Send transaction to `ArbSys`, note as the function is not view/pure function, we need to send transaction with gas cost: ``` cast send 0x0000000000000000000000000000000000000064 "sayHi()(string)" @@ -266,7 +266,6 @@ You should see `logs` field within the transaction receipt like this: From the `logs` field, we can see the topics[0] is `0xa937..cfa`, which is the event signature of `Hi(address)`, you can check it using [4 byte directory](https://www.4byte.directory/event-signatures/?bytes_signature=0xa9378d5bd800fae4d5b8d4c6712b2b64e8ecc86fdc831cb51944000fc7c8ecfa), and topics[1] is `Your_address`. -