Node.js & Bare Quickstart
Get started with WDK in Node.js or Bare runtime environments in 3 minutes
What You'll Build
Prerequisites
Tool
Version
Why You Need It
Tool
Version
Why You Need It
"type": "module"Get started with WDK in Node.js or Bare runtime environments in 3 minutes
"type": "module"Was this helpful?
mkdir wdk-quickstart && cd wdk-quickstart && npm init -y && npm pkg set type=modulenpm install @tetherto/wdk @tetherto/wdk-wallet-evm @tetherto/wdk-wallet-tron @tetherto/wdk-wallet-btcimport WDK from '@tetherto/wdk'
import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
import WalletManagerTron from '@tetherto/wdk-wallet-tron'
import WalletManagerBtc from '@tetherto/wdk-wallet-btc'
async function main() {
console.log('Starting WDK App...')
try {
// Your code will go here
} catch (error) {
console.error('Application error:', error.message)
process.exit(1)
}
}
// Run the application
main() try {
const seedPhrase = WDK.getRandomSeedPhrase()
console.log('Generated seed phrase:', seedPhrase)
} catch (error) {
console.error('Application error:', error.message)
}// Add this code after the seed phrase generation
console.log('Registering wallets...')
const wdkWithWallets = new WDK(seedPhrase)
.registerWallet('ethereum', WalletManagerEvm, {
provider: 'https://eth.drpc.org'
})
.registerWallet('tron', WalletManagerTron, {
provider: 'https://api.trongrid.io'
})
.registerWallet('bitcoin', WalletManagerBtc, {
network: 'mainnet',
host: 'electrum.blockstream.info',
port: 50001
})
console.log('Wallets registered for Ethereum, TRON, and Bitcoin')// Add this code after the wallet registration
console.log('Retrieving accounts...')
const accounts = {
ethereum: await wdkWithWallets.getAccount('ethereum', 0),
tron: await wdkWithWallets.getAccount('tron', 0),
bitcoin: await wdkWithWallets.getAccount('bitcoin', 0)
}
console.log('Resolving addresses:')
for (const [chain, account] of Object.entries(accounts)) {
const address = await account.getAddress()
console.log(` ${chain.toUpperCase()}: ${address}`)
}// Add this code after the address resolution
console.log('Checking balances...')
for (const [chain, account] of Object.entries(accounts)) {
const balance = await account.getBalance()
console.log(` ${chain.toUpperCase()}: ${balance.toString()} units`)
}import WDK from '@tetherto/wdk'
import WalletManagerEvm from '@tetherto/wdk-wallet-evm'
import WalletManagerTron from '@tetherto/wdk-wallet-tron'
import WalletManagerBtc from '@tetherto/wdk-wallet-btc'
async function main() {
console.log('Starting WDK App...')
try {
const seedPhrase = WDK.getRandomSeedPhrase()
console.log('Generated seed phrase:', seedPhrase)
console.log('Registering wallets...')
const wdkWithWallets = new WDK(seedPhrase)
.registerWallet('ethereum', WalletManagerEvm, {
provider: 'https://eth.drpc.org'
})
.registerWallet('tron', WalletManagerTron, {
provider: 'https://api.trongrid.io'
})
.registerWallet('bitcoin', WalletManagerBtc, {
network: 'mainnet',
host: 'electrum.blockstream.info',
port: 50001
})
console.log('Wallets registered for Ethereum, TRON, and Bitcoin')
const accounts = {
ethereum: await wdkWithWallets.getAccount('ethereum', 0),
tron: await wdkWithWallets.getAccount('tron', 0),
bitcoin: await wdkWithWallets.getAccount('bitcoin', 0)
}
console.log('Resolving addresses:')
for (const [chain, account] of Object.entries(accounts)) {
const address = await account.getAddress()
console.log(` ${chain.toUpperCase()}: ${address}`)
}
console.log('Checking balances...')
for (const [chain, account] of Object.entries(accounts)) {
const balance = await account.getBalance()
console.log(` ${chain.toUpperCase()}: ${balance.toString()} units`)
}
console.log('Application completed successfully!')
process.exit(0)
} catch (error) {
console.error('Application error:', error.message)
process.exit(1)
}
}
// Run the application
main()node app.jsbare app.jsStarting WDK App...
Generated seed phrase: abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
Registering wallets...
Wallets registered for Ethereum, TRON, and Bitcoin
Resolving addresses:
ETHEREUM: 0x742d35Cc6634C0532925a3b8D9C5c8b7b6e5f6e5
TRON: TLyqzVGLV1srkB7dToTAEqgDSfPtXRJZYH
BITCOIN: 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
Checking balances...
ETHEREUM: 0 units
TRON: 0 units
BITCOIN: 0 units
Application completed successfully!npm install @tetherto/wdk-wallet-solanaimport WalletManagerSolana from '@tetherto/wdk-wallet-solana'
// New or existing WDK instance
const wdk = new WDK(seedPhrase)
wdk.registerWallet('solana', WalletManagerSolana, {
rpcUrl: 'https://api.mainnet-beta.solana.com',
wsUrl: 'wss://api.mainnet-beta.solana.com'
})
for (const [chain, account] of Object.entries(accounts)) {
try {
const quote = await account.quoteSendTransaction({
to: await account.getAddress(),
value: chain === 'bitcoin' ? 100000000n : chain === 'tron' ? 1000000n : 1000000000000000000n
})
console.log(` ${chain.toUpperCase()}: ${quote.fee.toString()} units`)
} catch (error) {
console.log(` ${chain.toUpperCase()}: Unable to estimate`)
}
}const result = await ethAccount.sendTransaction({
to: '0x742d35Cc6634C05...a3b8D9C5c8b7b6e5f6e5',
value: 1000000000000000000n // 1 ETH
})
console.log('Transaction hash:', result.hash)npm install @tetherto/wdk-protocol-swap-velora-evmimport VeloraProtocolEvm from '@tetherto/wdk-protocol-swap-velora-evm'
wdk.registerProtocol('ethereum', 'swap-velora-evm', VeloraProtocolEvm, {
provider: 'https://eth.drpc.org'
})