Closed shanejonas closed 2 months ago
Preview published: fix/send-transaction-example
This pull request corrects the structure of the code snippet by properly formatting the params object within the .request() method call.
Changes Made
Adjusted the code snippet to ensure that the params object is properly formatted within the .request() method call. Moved the params object inside the .request() method call to adhere to correct syntax.
Before:
params: [
{
from: "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
to: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
// 30400
gas: "0x76c0",
// 10000000000000
gasPrice: "0x9184e72a000",
// 2441406250
value: "0x9184e72a",
data: "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
},
];
provider // Or window.ethereum if you don't support EIP-6963.
.request({
method: "eth_sendTransaction",
params,
})
.then((result) => {
// The result varies by RPC method.
// For example, this method returns a transaction hash hexadecimal string upon success.
})
.catch((error) => {
// If the request fails, the Promise rejects with an error.
});
After:
provider // Or window.ethereum if you don't support EIP-6963.
.request({
method: "eth_sendTransaction",
params: [
{
from: "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
to: "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
// 30400
gas: "0x76c0",
// 10000000000000
gasPrice: "0x9184e72a000",
// 2441406250
value: "0x9184e72a",
data: "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675",
},
]
})
.then((result) => {
// The result varies by RPC method.
// For example, this method returns a transaction hash hexadecimal string upon success.
})
.catch((error) => {
// If the request fails, the Promise rejects with an error.
});
Reason for Change
The previous version of the code snippet had the params object defined outside of the .request() method call, which is not valid syntax either.
params: []
isnt valid, should be: const params = [{stuffinhere}]
And it's best to just have it in the request object to be super clear.
This change ensures that the code is correctly structured, making it easier to understand.
Preview published: fix/send-transaction-example
Description
The code example in this provider api markdown isn't valid code. This fixes that.