Ethereum: How to send an eip-4844 (blob transaction / type 3 transaction)?
Sending a Type 3 Transaction on Ethereum: Step by Step
Starting with Ethereum 2.0, Type 3 Transactions (EIP-4844) allow for more advanced and flexible interactions with smart contracts. In this article, we will show you how to send a Type 3 transaction using a blob transaction.
What is an EIP-4844 transaction?
An EIP-4844 transaction is a new type of transaction that allows you to transfer data from one address to another without the need for a separate function call. This means that you can now communicate with smart contracts more efficiently.
How to send a Type 3 transaction
If you want to send a Type 3 transaction on Ethereum, you need to use the “eth_sendTransaction” method provided by the web3 library. Here is an example of how to do it:
const web3 = request('web3');
const network = new web3.providers.HttpProvider('
const contractAddress = '0x...'; // Replace with your contract address
const data = 'Hello, world!';
const gasPrice = 20; Optional gas price (optional)
web3.eth.sendTransaction({
from: network accounts.get('YOUR ACCOUNTS ADDRESS'), // You need to get the 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 the current nonce (optional)
value: web3.utils.toWei('1', 'ether'), // Sets the value to 1 ether
data,
gas price: gas price
}, (error, transactionHash) => {
if (error) {
console.error(error);
} else {
console.log(Transaction sent successfully! Transaction hash: ${transactionHash}
);
}
});
Raw API Calls Using Type 3 Transactions
Here is an example of how to send a Type 3 transaction using the “web3” library:
const web3 = request('web3');
const network = new web3.providers.HttpProvider('
const contractAddress = '0x...'; // Replace with your address. contract
const data = 'Hello, world!';
const gasPrice = 20; Optional gas price (optional)
web3.eth.sendTransaction({
from: network accounts.get('YOUR ACCOUNTS ADDRESS'), // Need to get the 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 the current nonce (optional)
value: web3.utils.toWei('1', 'ether'), // Set 1 ether
data,
gas price: gas price
}, {
jsonrpc: "2.0",
method: "eth_sendTransaction"
})
3. Sending a type 3 transaction with blob data
If you want to send a type 3 transaction with blob data, you need to use the “eth_sendTransaction” method and specify the “jsonrpc” parameter as “2.0”. Then you can pass the blob data as a string:
const web3 = request('web3');
const network = new web3.providers.HttpProvider('
const contractAddress = '0x...'; // Replace with your contract address
constant gasPrice = 20; Optional gas price (optional)
const data = Buffer.from('Hello, world!', 'utf8'); // Create a string data blob
web3.eth.sendTransaction({
from: network accounts.get('YOUR ACCOUNTS ADDRESS'), // Need to get the sender's account address
jsonrpc: "2.0",
method: "eth_sendTransaction"
}, {
parameters: [data],
gas price,
gas: 2000000, // Set a high gas limit to avoid gas errors
nonce: web3.utils.toHex(web3.eth.getTransactionCount(network.accounts[0])), // Get the current nonce (optional)
value: web3.utils.toWei('1', 'ether'), // Set 1 ether
data,
jsonrpcVersion: 2.0
})
Remember to replace the “ACCOUNTS ADDRESS” element. and the “PROJECTID” with the actual address of the account. Ethereum and projectID.
Hope this helps!