sendTransaction
Creates, signs, and sends a new transaction to the network.
Usage
import { , } from "./config";
const = await .({
,
: "cfx:...",
: 1000000000000000000n,
});
// '0x...'import { , } from 'cive'
import { } from 'cive/chains'
export const = ({
: ,
: (.!),
})
export const [] = await .();
โ JSON-RPC Account // export const account = privateKeyToAccount("0x...", {networkId: mainnet.id});
โ Local AccountAccount Hoisting
If you do not wish to pass an account to every sendTransaction, you can also hoist the Account on the Wallet Client (see config.ts).
import { } from "./client";
const = await .({
: "cfx:...",
: 1000000000000000000n,
});
// '0x...'import { createWalletClient, custom } from "cive";
import { mainnet } from "cive/chains";
const [account] = await window.fluent.request({
method: "cfx_requestAccounts",
});
export const walletClient = createWalletClient({
account,
chain: mainnet,
transport: custom(window.fluent!),
});import { , } from "cive";
import { } from "cive/accounts";
import { } from "cive/chains";
export const = ({
: ("0x...", { : . }),
: ,
: (),
});Returns
The Transaction hash.
Parameters
account
- Type:
Account | Address
The Account to send the transaction from.
Accepts a JSON-RPC Account or Local Account (Private Key, etc).
const = await .({
: "cfx:...",
: "cfx:...",
: 1000000000000000000n,
});to
- Type:
0x${string}
The transaction recipient or contract address.
const = await .({
,
: "cfx:...",
: 1000000000000000000n,
: 1,
});accessList (optional)
- Type:
AccessList
The access list.
const = await .({
: [
{
: "0x1",
: ["0x1"],
},
],
,
: "cfx:...",
});data (optional)
- Type:
0x${string}
A contract hashed method call with encoded args.
const = await .({
: "cfx:...",
,
: "cfx:...",
: 1000000000000000000n,
});gasPrice (optional)
- Type:
bigint
The price (in wei) to pay per gas. Only applies to Legacy Transactions.
import { , } from "cive/utils";
const = await .({
,
: ("20"),
: "cfx:...",
: ("1"),
});maxFeePerGas (optional)
- Type:
bigint
Total fee per gas (in wei), inclusive of maxPriorityFeePerGas. Only applies to EIP-1559 Transactions
import { , } from "cive/utils";
const = await .({
,
: ("20"),
: "cfx:...",
: ("1"),
});maxPriorityFeePerGas (optional)
- Type:
bigint
Max priority fee per gas (in wei). Only applies to EIP-1559 Transactions
import { , } from "cive/utils";
const = await .({
,
: ("20"),
: ("2"),
: "cfx:...",
: ("1"),
});nonce (optional)
- Type:
number
Unique number identifying this transaction.
const = await .({
,
: "cfx:...",
: 1000000000000000000n,
: 1,
});value (optional)
- Type:
bigint
Value in wei sent with this transaction.
import { , } from "cive/utils";
const = await .({
,
: "cfx",
: ("1"),
: 1,
});Tips
- For dapps: When using this action, it is assumed that the user has connected to their wallet (e.g. given permission for the dapp to access their accounts via
requestAddresses). You can also check if the user has granted access to their accounts viagetAddresses
JSON-RPC Methods
- JSON-RPC Accounts:
- Local Accounts: