# Accounts

Backend wallets are server-side wallets that enable your application to sign transactions, manage assets, and interact with blockchains programmatically. Each backend wallet corresponds to a private/public key pair, with the private key securely stored and managed by Openfort.

## Creating accounts

Create new backend accounts to manage keys programmatically.

:::code-group

```ts [Ethereum]
import 'dotenv/config'
import Openfort from '@openfort/openfort-node'

const openfort = new Openfort(process.env.OPENFORT_SECRET_KEY!, {
  walletSecret: process.env.OPENFORT_WALLET_SECRET!,
})

// Create an Ethereum backend account
const account = await openfort.accounts.evm.backend.create();

console.log('Account ID:', account.id);
console.log('Address:', account.address);
```

```ts [Solana]
import 'dotenv/config'
import Openfort from '@openfort/openfort-node'

const openfort = new Openfort(process.env.OPENFORT_SECRET_KEY!, {
  walletSecret: process.env.OPENFORT_WALLET_SECRET!,
})

// Create a Solana backend account
const account = await openfort.accounts.solana.backend.create();

console.log('Account ID:', account.id);
console.log('Address:', account.address);
```

:::

## Listing accounts

Retrieve all backend accounts in your project with pagination support.

:::code-group

```ts [Ethereum]
import 'dotenv/config'
import Openfort from '@openfort/openfort-node'

const openfort = new Openfort(process.env.OPENFORT_SECRET_KEY!, {
  walletSecret: process.env.OPENFORT_WALLET_SECRET!,
})

// List all Ethereum backend accounts
const result = await openfort.accounts.evm.backend.list({ limit: 10 });

console.log(`Found ${result.total} accounts:`);
for (const account of result.accounts) {
  console.log(`  - ${account.address} (${account.id})`);
}

// Paginate through results
const nextPage = await openfort.accounts.evm.backend.list({
  limit: 10,
  skip: 10,
});
```

```ts [Solana]
import 'dotenv/config'
import Openfort from '@openfort/openfort-node'

const openfort = new Openfort(process.env.OPENFORT_SECRET_KEY!, {
  walletSecret: process.env.OPENFORT_WALLET_SECRET!,
})

// List all Solana backend accounts
const result = await openfort.accounts.solana.backend.list({ limit: 10 });

console.log(`Found ${result.total} accounts:`);
for (const account of result.accounts) {
  console.log(`  - ${account.address} (${account.id})`);
}
```

:::

## Retrieving accounts

Retrieve a specific account by its ID or blockchain address.

:::info
When retrieving by address, use the exact stored format: **Ethereum** addresses must be [EIP-55 checksummed](https://eips.ethereum.org/EIPS/eip-55) (mixed-case hex), and **Solana** addresses must be [Base58](https://solana.com/docs/more/exchange#basic-validation) encoded.
:::

:::code-group

```ts [Ethereum]
import 'dotenv/config'
import Openfort from '@openfort/openfort-node'

const openfort = new Openfort(process.env.OPENFORT_SECRET_KEY!, {
  walletSecret: process.env.OPENFORT_WALLET_SECRET!,
})

// Retrieve by ID
const accountById = await openfort.accounts.evm.backend.get({
  id: 'acc_...',
});

// Retrieve by address
const accountByAddress = await openfort.accounts.evm.backend.get({
  address: '0x1234567890123456789012345678901234567890',
});
```

```ts [Solana]
import 'dotenv/config'
import Openfort from '@openfort/openfort-node'

const openfort = new Openfort(process.env.OPENFORT_SECRET_KEY!, {
  walletSecret: process.env.OPENFORT_WALLET_SECRET!,
})

// Retrieve by ID
const accountById = await openfort.accounts.solana.backend.get({
  id: 'acc_...',
});

// Retrieve by address
const accountByAddress = await openfort.accounts.solana.backend.get({
  address: 'So1anaAddress...',
});
```

:::

## Importing accounts

Import existing wallets into Openfort by providing the private key. This enables you to migrate existing wallets or use keys generated elsewhere.

:::code-group

```ts [Ethereum]
import 'dotenv/config'
import Openfort from '@openfort/openfort-node'

const openfort = new Openfort(process.env.OPENFORT_SECRET_KEY!, {
  walletSecret: process.env.OPENFORT_WALLET_SECRET!,
})

// Import an Ethereum account using a hex-encoded private key
const account = await openfort.accounts.evm.backend.import({
  privateKey: '0x0123456789abcdef...', // 32-byte hex-encoded private key
});

console.log('Imported account:', account.address);
```

```ts [Solana]
import 'dotenv/config'
import Openfort from '@openfort/openfort-node'

const openfort = new Openfort(process.env.OPENFORT_SECRET_KEY!, {
  walletSecret: process.env.OPENFORT_WALLET_SECRET!,
})

// Import a Solana account
// Accepts both base58 (Phantom format) and hex-encoded private keys
const account = await openfort.accounts.solana.backend.import({
  privateKey: '4YFq9y5f5hi77Bq8kDCE6VgqoAq...', // base58 or hex format
});

console.log('Imported account:', account.address);
```

:::

:::warning
When importing accounts, ensure your private keys are transmitted securely. Never expose private keys in client-side code or logs.
:::

## Exporting accounts

Export the private key from a backend account. This is useful for migrating to another provider or for backup purposes.

:::code-group

```ts [Ethereum]
import 'dotenv/config'
import Openfort from '@openfort/openfort-node'

const openfort = new Openfort(process.env.OPENFORT_SECRET_KEY!, {
  walletSecret: process.env.OPENFORT_WALLET_SECRET!,
})

// Export the private key
const privateKey = await openfort.accounts.evm.backend.export({
  id: 'acc_...',
});

console.log('Private key:', `0x${privateKey}`);
```

```ts [Solana]
import 'dotenv/config'
import Openfort from '@openfort/openfort-node'

const openfort = new Openfort(process.env.OPENFORT_SECRET_KEY!, {
  walletSecret: process.env.OPENFORT_WALLET_SECRET!,
})

// Export the private key (returns base58 format)
const privateKey = await openfort.accounts.solana.backend.export({
  id: 'acc_...',
});

console.log('Private key (base58):', privateKey);
```

:::

:::danger
Exporting private keys is a sensitive operation. Store exported keys securely and never expose them in logs, client-side code, or insecure storage. Once exported, you are responsible for the security of the key.
:::

:::tip\[Runnable examples]
See the complete runnable examples for [EVM accounts](https://github.com/openfort-xyz/openfort-node/tree/main/examples/evm/accounts) and [Solana accounts](https://github.com/openfort-xyz/openfort-node/tree/main/examples/solana/accounts) in the Node SDK repository.
:::
