Ethereum - Getting Started (SDK)
Steps
Step_1: Get Started
To get started using EVM Wallet Providers, you would need to install @tatumio/evm-wallet-provider along with the Tatum SDK.
npm install @tatumio/evm-wallet-provider
Step_2: Generate a Mnemonic
Generating a mnemonic means creating a 24-word phrase that will be the foundation for your wallet. This phrase is like a master key from which all your wallet addresses and their private keys can be generated.
- Tatum does not store Mnemonics and or Private Keys.
- The responsibility of keeping your Mnemonics and Private Keys secure rests solely with you, the User.
- Additional information about Mnemonics and Private Keys is available in the following article.
The Ethereum Wallet Provider submodule helps in generating a mnemonic easily. This mnemonic phrase, also known as a seed phrase, is vital for creating and recovering wallets on Ethereum.
// Import the necessary library and initialize the SDK
import { EvmWalletProvider } from '@tatumio/evm-wallet-provider';
import { TatumSDK, Network, Ethereum } from '@tatumio/tatum';
const tatum = await TatumSDK.init<Ethereum>({network: Network.ETHEREUM,
configureWalletProviders: [
EvmWalletProvider,
]});
// Generate mnemonic using the EVM Wallet Provider submodule
const mnemonic = tatum.walletProvider.use(EvmWalletProvider).generateMnemonic();
console.log(mnemonic); // This will print the generated mnemonic
await tatum.destroy()
// Install with: npm install @tatumio/evm-wallet-provider @tatumio/tatum
const { EvmWalletProvider } = require("@tatumio/evm-wallet-provider");
const { TatumSDK, Network, Ethereum } = require("@tatumio/tatum");
(async () => {
try {
const tatum = await TatumSDK.init({ network: Network.ETHEREUM,
configureWalletProviders: [
EvmWalletProvider,
]
});
const mnemonic = await tatum.walletProvider.use(EvmWalletProvider).generateMnemonic();
console.log(mnemonic);
} catch (error) {
console.error("Error generating mnemonic:", error);
}
})();
await tatum.destroy()
Step_3: Generate XPUB
Generating an extended public key (xpub) is a way to allow the creation of public addresses without exposing the corresponding private keys. It's an important function for maintaining security while still being able to receive funds.
You can generate Xpub with or without mnemonic.
// Import the necessary library and initialize the SDK
import { EvmWalletProvider } from '@tatumio/evm-wallet-provider';
import { TatumSDK, Network, Ethereum } from '@tatumio/tatum';
const tatumSdk = await TatumSDK.init<Ethereum>({network: Network.ETHEREUM,
configureWalletProviders: [
EvmWalletProvider,
]});
// Generate xpub using the generated mnemonic
const xpubDetails = await tatumSdk.walletProvider.use(EvmWalletProvider)
.generateXpub(mnemonic);
console.log(xpubDetails.xpub); // This will print the generated xpub
await tatum.destroy()
// Install with: npm install @tatumio/evm-wallet-provider @tatumio/tatum
const { EvmWalletProvider } = require("@tatumio/evm-wallet-provider");
const { TatumSDK, Network, Ethereum } = require("@tatumio/tatum");
(async () => {
try {
const tatumSdk = await TatumSDK.init({ network: Network.ETHEREUM,
configureWalletProviders: [
EvmWalletProvider,
]});
const xpubDetails = await tatumSdk.walletProvider.use(EvmWalletProvider).generateXpub(mnemonic);
console.log(xpubDetails.xpub);
} catch (error) {
console.error("Error generating xpub:", error);
}
})();
await tatum.destroy()
Step_4: Generate Private Key
Creating a private key is creating a unique and secret key that belongs to you. This key is crucial for accessing and controlling your funds.
// Import the necessary library and initialize the SDK
import { EvmWalletProvider } from '@tatumio/evm-wallet-provider';
import { TatumSDK, Network, Ethereum } from '@tatumio/tatum';
const tatumSdk = await TatumSDK.init<Ethereum>({network: Network.ETHEREUM,
configureWalletProviders: [
EvmWalletProvider,
]});
// Generate private key from mnemonic
const privateKey = await tatumSdk.walletProvider.use(EvmWalletProvider)
.generatePrivateKeyFromMnemonic(mnemonic, 0);
console.log(privateKey); // This will print the generated private key
await tatum.destroy()
// Install with: npm install @tatumio/evm-wallet-provider @tatumio/tatum
const { EvmWalletProvider } = require("@tatumio/evm-wallet-provider");
const { TatumSDK, Network, Ethereum } = require("@tatumio/tatum");
(async () => {
try {
const tatumSdk = await TatumSDK.init({ network: Network.ETHEREUM,
configureWalletProviders: [
EvmWalletProvider,
]});
const privateKey = await tatumSdk.walletProvider.use(EvmWalletProvider)
.generatePrivateKeyFromMnemonic(mnemonic, 0);
console.log(privateKey);
} catch (error) {
console.error("Error generating private key:", error);
}
})();
await tatum.destroy()
Step_5: Generate Address
Generating an address is about creating a public address where others can send you funds. It's like an account number in the blockchain world.
You can generate an address with both Mnemonic or Xpub
// Import the necessary library and initialize the SDK
import { EvmWalletProvider } from '@tatumio/evm-wallet-provider';
import { TatumSDK, Network, Ethereum } from '@tatumio/tatum';
const tatumSdk = await TatumSDK.init<Ethereum>({network: Network.ETHEREUM,
configureWalletProviders: [
EvmWalletProvider,
]});
// Generate address from mnemonic or xpub
const addressFromMnemonic = await tatumSdk.walletProvider
.use(EvmWalletProvider).generateAddressFromMnemonic(mnemonic, 0);
const addressFromXpub = await tatumSdk.walletProvider
.use(EvmWalletProvider).generateAddressFromXpub(xpubDetails.xpub, 0);
// This will print the generated address from mnemonic
console.log(addressFromMnemonic);
// This will print the generated address from xpub
console.log(addressFromXpub);
await tatum.destroy()
// Install with: npm install @tatumio/evm-wallet-provider @tatumio/tatum
const { EvmWalletProvider } = require("@tatumio/evm-wallet-provider");
const { TatumSDK, Network, Ethereum } = require("@tatumio/tatum");
(async () => {
try {
const tatumSdk = await TatumSDK.init({ network: Network.ETHEREUM,
configureWalletProviders: [
EvmWalletProvider,
]});
const addressFromMnemonic = await tatumSdk.walletProvider
.use(EvmWalletProvider).generateAddressFromMnemonic(mnemonic, 0);
const addressFromXpub = await tatumSdk.walletProvider
.use(EvmWalletProvider).generateAddressFromXpub(xpubDetails.xpub, 0);
console.log(addressFromMnemonic);
console.log(addressFromXpub);
} catch (error) {
console.error("Error generating address:", error);
}
})();
await tatum.destroy()
Step_6: Sign and Broadcast a Transaction
Signing and broadcasting a transaction is about authorising a transfer of funds or interaction with a smart contract and then sending that authorisation to the blockchain to be processed.
// Import the necessary library and initialize the SDK
import { EvmWalletProvider } from '@tatumio/evm-wallet-provider';
import { TatumSDK, Network, Ethereum } from '@tatumio/tatum';
const tatumSdk = await TatumSDK.init<Ethereum>({network: Network.ETHEREUM,
configureWalletProviders: [
EvmWalletProvider,
]});
// Define your transaction details
const payload = {
privateKey: 'YOUR_PRIVATE_KEY',
// other fields for your transaction...
}
// Sign and broadcast the transaction using the EVM Wallet Provider submodule
const txHash = await tatumSdk.walletProvider.use(EvmWalletProvider)
.signAndBroadcast(payload);
// This will print the transaction hash of the broadcasted transaction
console.log(txHash);
await tatum.destroy()
// Install with: npm install @tatumio/evm-wallet-provider @tatumio/tatum
const { EvmWalletProvider } = require("@tatumio/evm-wallet-provider");
const { TatumSDK, Network, Ethereum } = require("@tatumio/tatum");
(async () => {
try {
const tatumSdk = await TatumSDK.init({ network: Network.ETHEREUM,
configureWalletProviders: [
EvmWalletProvider,
]});
const payload = {
privateKey: 'YOUR_PRIVATE_KEY',
// other fields for your transaction...
}
const txHash = await tatumSdk.walletProvider.use(EvmWalletProvider)
.signAndBroadcast(payload);
console.log(txHash);
} catch (error) {
console.error("Error signing and broadcasting transaction:", error);
}
})();
await tatum.destroy()
Good to Know
- Fee Estimates may fluctuate one way or the other, within seconds.
- Tatum Mainnet Fee Estimates are generally in line with other providers.
- The Testnet Fee Estimate is generally unreliable. Since testnet coins have "no value", users tend to set random amounts greatly skewing the estimates.
- Be mindful of Tatum's derivation path. Find additional information in the following article.
- To transfer tokens on the POLYGON network, check the following article.
- Familiarize yourself with the Safety & Security Basics in the following article.
Updated 5 months ago