Send Native (daccSendNative)
A function to send native tokens
The daccSendNative function allows you to send native cryptocurrency (ETH, etc.) from a Dacc wallet to any destination address. It handles the transaction signing and broadcasting using the encrypted wallet data.
Import
import { daccSendNative } from 'dacc-js';Usage
import { daccSendNative } from 'dacc-js';
import { optimismSepolia } from 'viem/chains'; // used `viem` - npm i viem
const tx = await daccSendNative({
// account: "0xPrivatekey...", // Can call with `allowDaccWallet` function
daccPublickey: 'daccPublickey_0x123_XxX..',
// address: "0xYourAccountAddress..", // Only the address created is set to `publicEncryption: true`
passwordSecretkey: "my+Password#123..",
network: optimismSepolia,
to: "0xRecipientAddress..",
amount: 0.0000001,
});
console.log("tx:", tx);Arguments
| Parameter | Type | Description |
|---|---|---|
account | Account or 0x${string} | Conditional: The account to use for signing (Account object is private key). |
daccPublickey | string | Conditional: The encrypted wallet data from createDaccWallet. |
address | 0x${string} | Conditional: wallet address from a created with createDaccWallet in publicEncryption: true mode (can use instead of daccPublickey). |
passwordSecretkey | string | Conditional: The user's password used to decrypt the wallet. |
network | Chain | The blockchain network object to send the transaction on. |
to | 0x${string} | The recipient's wallet address. |
amount | number | The amount of native tokens to send. |
Return Value
The response result is an object containing {txHash, chainId, from, to, amount}
Parameters
account (conditional)
- Type:
Account|0x${string}
The user's account to use for signing the transaction.
const tx = await daccSendNative({
account: "0xPrivatekey...", // Can call with `allowDaccWallet` function
// daccPublickey: 'daccPublickey_0x123_XxX..', //
// address: "0xYourAccountAddress..", //
// passwordSecretkey: 'my+Password#123..', //
network: optimismSepolia,
to: "0xRecipientAddress..",
amount: 0.001
});daccPublickey (conditional)
- Type:
string
The user's encrypted public key to address.
daccPublickey is the most reliable addressing solution and supports all types of data storage using
daccPublickey.
const tx = await daccSendNative({
// account: "0xPrivatekey...", //
daccPublickey: 'daccPublickey_0x123_XxX..',
passwordSecretkey: 'my+Password#123..',
network: optimismSepolia,
to: "0xRecipientAddress..",
amount: 0.001
});address (optional)
- Type:
0x${string}
The encrypted wallet data returned from createDaccWallet.
const tx = await daccSendNative({
// account: "0xPrivatekey...", //
// daccPublickey: 'daccPublickey_0x123_XxX..', // Match with address
address: "0xYourAccountAddress..", // Only the address created is set to `publicEncryption: true`
passwordSecretkey: 'my+Password#123..',
network: optimismSepolia,
to: "0xRecipientAddress..",
amount: 0.0001
});passwordSecretkey (conditional)
- Type:
string
The same password used when creating the wallet.
const tx = await daccSendNative({
daccPublickey: "daccPublickey_0x123_XxX..",
passwordSecretkey: "my+Password#123..",
network: optimismSepolia,
to: "0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC",
amount: 0.001
});network
- Type:
Chain
The blockchain network object to send the transaction on.
const tx = await daccSendNative({
daccPublickey: "daccPublickey_0x123_XxX..",
passwordSecretkey: "my+Password#123..",
network: optimismSepolia // used `viem`
// network: myCustomChain // For - Custom Chain Network
to: "0xRecipientAddress..",
amount: 0.001
});to
- Type:
0x${string}
The recipient's wallet address.
const tx = await daccSendNative({
daccPublickey: "daccPublickey_0x123_XxX..",
passwordSecretkey: "my+Password#123..",
to: "0xRecipientAddress..",
amount: 0.001,
network: optimismSepolia
});amount
- Type:
number
The amount of native tokens to send.
const tx = await daccSendNative({
daccPublickey: "daccPublickey_0x123_XxX..",
passwordSecretkey: "my+Password#123..",
to: "0xRecipientAddress..",
amount: 0.001,
network: optimismSepolia
});Examples
Send using private key directly
import { daccSendNative } from "dacc-js";
import { optimismSepolia } from "viem/chains";
// Send tokens using account private key (for testing)
const tx = await daccSendNative({
account: "0xPrivatekey...",
network: optimismSepolia,
to: "0xRecipient..",
amount: 0.001,
});
console.log("Test transaction:", tx);Send ETH using daccPublickey
import { daccSendNative } from "dacc-js";
import { mainnet } from "viem/chains";
// Send 0.1 ETH to another wallet
const transaction = await daccSendNative({
daccPublickey: "daccPublickey_0x123_XxX..",
passwordSecretkey: 'my+Password#123..',
network: mainnet,
to: "0xRecipient..",
amount: 0.000001,
});
console.log("Transaction sent:", transaction.txHash);Send using Dacc wallet address
import { daccSendNative } from "dacc-js";
import { sepolia } from "viem/chains";
// Send using wallet address (must be created with publicEncryption: true)
const result = await daccSendNative({
address: "0xYourAccountAddress..",
passwordSecretkey: 'my+Password#123..',
network: sepolia,
to: "0xRecipient..",
amount: 0.05,
});
console.log(`Sent ${result.amount} ETH from ${result.from} to ${result.to}`);
console.log(`Transaction hash: ${result.txHash}`);Send with custom chain
import { daccSendNative } from "dacc-js";
import { defineChain } from "viem";
// Define custom blockchain
const myCustomChain = defineChain({
id: 123456,
name: "My Custom Chain",
network: "myCustomChain",
nativeCurrency: { name: "ETH", symbol: "ETH", decimals: 18 },
rpcUrls: {
default: { http: ["https://rpc-example.com"] }
},
blockExplorers: {
default: { name: 'Explorer', url: 'https://explorer-example.com' },
},
});
const tx = await daccSendNative({
daccPublickey: "daccPublickey_0x123_XxX..",
passwordSecretkey: 'my+Password#123..',
network: myCustomChain,
to: "0xRecipient..",
amount: 0.02,
});
console.log("Arbitrum transaction:", tx);