Sending Type 3 transaction to Ethereum: Step by step wizard
From Ethereum 2.0, type 3 transactions (EIP-4844) allow more advanced and more flexible intelligent interactions. In this article, we deal with how to send a type 3 transaction using the Blob transaction.
What is the EIP-4844 transaction?
The EIP-4844 transaction is a new type of transaction that allows data to transfer data from one address to another, without the need for a separate functional call. This means that you can now interact with smart contracts more effectively.
How to send type 3 transaction
To send a type 3 transaction to Ethereum, you must use the et_sendtransaction
method provided by the” Web3. Here is an example of how to do this:
Javascript
Const Web3 = Require (‘Web3’);
Const network = new web3.Providers.httpprovider (‘
Const Contractaddress = ‘0x …’; // replace the contract address
Const data = ‘Hi, the world!’;
Const Gasprice = 20; // Optional gas price (optional)
Web3.eth.sendtransaction ({{
By: Network ACCOUNT.GET (“Your Account Address”), // You must get your sender’s account address
Gas: 2000000, // Set a high gas limit to avoid gas errors
NONCE: Web3.utils.Tohex (Web3.eth.gettransactionCount (Network.accounts [0])), // Get Current Nonce (Optional)
Value: Web3.utils.towei (‘1’, ‘ether’), // Set 1 ether
data,
Gasprice: Gasprice
}, (error, transactionshesh) => {
IF (ERROR) {
Console.error (Error);
} Else {
Console.log (transaction sent successfully! Transaction hash: $ {transactionHash}
);
}
});
`
RAW API calls using type 3 transaction
Here is an example of how to send a type 3 transaction using the “Web3:
Javascript
Const Web3 = Require (‘Web3’);
Const network = new web3.Providers.httpprovider (‘
Const Contractaddress = ‘0x …’; // replace the contract address
Const data = ‘Hi, the world!’;
Const Gasprice = 20; // Optional gas price (optional)
Web3.eth.sendtransaction ({{
By: Network ACCOUNT.GET (“Your Account Address”), // You must get your sender’s account address
Gas: 2000000, // Set a high gas limit to avoid gas errors
NONCE: Web3.utils.Tohex (Web3.eth.gettransactionCount (Network.accounts [0])), // Get Current Nonce (Optional)
Value: Web3.utils.towei (‘1’, ‘ether’), // Set 1 ether
data,
Gasprice: Gasprice
}, {{
JSONRPC: “2.0”,
Method: “ET_SENDTRANSACTION”
})
`
Sending Type 3 transaction with Blob data
To send a type 3 transaction using the Blob data, you must use the et_sendtransaction
and determine the parameter ‘Jsonrpcas
2.0. You can then pass the Blob data as a chain:
Javascript
Const Web3 = Require (‘Web3’);
Const network = new web3.Providers.httpprovider (‘
Const Contractaddress = ‘0x …’; // replace the contract address
Const Gasprice = 20; // Optional gas price (optional)
Const data = buffer.from (‘Hi, World!’, ‘Utf8’); // Create a Blob of Chain Data
Web3.eth.sendtransaction ({{
By: Network ACCOUNT.GET (“Your Account Address”), // You must get your sender’s account address
JSONRPC: “2.0”,
Method: “ET_SENDTRANSACTION”
}, {{
params: [data],
gas,
Gas: 2000000, // Set a high gas limit to avoid gas errors
NONCE: Web3.utils.Tohex (Web3.eth.gettransactionCount (Network.accounts [0])), // Get Current Nonce (Optional)
Value: Web3.utils.towei (‘1’, ‘ether’), // Set 1 ether
data,
Jsonrpcversion: 2.0
})
`
Please note that you will have to replace the address “your accounts” and “your project_id” with the actual address of the Ethereum account and the project ID.
I hope it will help!