Web3 Client SDK

Flutter based sdk that provides below wallet functions:

  • generate mnemonic
  • get mnemonic
  • import mnemonic
  • destroy mnemonic
  • get address
  • get balance
  • create & sign transaction
  • send transaction

Usage

Generate mnemonic

import 'package:web3_cloud_sdk/client_sdk.dart' as clientsdk;

// strength can be set in 2nd param between 128 - 256
// strength should be either of 128, 160, 192, 224, 256 bits
// 128 => 12 words
// 256 => 24 words
final mnemonic = await clientsdk.generateMnemonic(walletId, 256);

Create wallet

import 'package:web3_cloud_sdk/client_sdk.dart' as clientsdk;
import 'package:web3_cloud_sdk/ethereum_lib.dart' as ethereum;

final networkParam = ethereum.NetworkParam(
    clientsdk.ChainId.ethereumGoerli,
    clientsdk.NetworkId.ethereumGoerli,
    dotenv.env['ETH_RPC_URL_GOERLI']!);

final sdk = clientsdk.SdkBase();
final wallet = await sdk.evm.createWallet(walletId, networkParam);

Get balance

import 'package:web3_cloud_sdk/ethereum_lib.dart' as ethereum;

// get ether balance
// account index: 0 - 4294967295
final etherBalance = await wallet.account(0).balance();

// get LINK balance on goerli testnet
final ftBalance = await wallet.account(0).ftBalance(ethereum.Erc20ContractAddress.goerliLink);

Sign transaction (transfer ether)

import 'package:web3_cloud_sdk/client_sdk.dart' as clientsdk;
import 'package:web3_cloud_sdk/ethereum_lib.dart' as ethereum;

final signedTx = await ethereum.TxBuilder()
    .value(ethereum.etherToWei('0.0001'))
    .gasPrice('80000000000') // 80 Gwei
    .gasLimit(21000)
    .to(dotenv.env['TO_ADDRESS']!)
    .chainId(clientsdk.ChainId.ethereumGoerli)
    .nonce(1) // optional: nonce will be taken from the connected node when not specified
    .sign(wallet.account(0))
    .build();

Sign transaction (transfer erc20)

import 'package:web3_cloud_sdk/client_sdk.dart' as clientsdk;
import 'package:web3_cloud_sdk/ethereum_lib.dart' as ethereum;

// erc20 contract
final erc20Contract = ethereum.Erc20Contract(ethereum.Erc20ContractAddress.goerliLink);

final signedTx = await ethereum.TxBuilder()
    .value('0')
    .gasPrice('80000000000') // 80 Gwei
    .gasLimit(250000)
    .to(ethereum.Erc20ContractAddress.goerliLink)
    .chainId(clientsdk.ChainId.ethereumGoerli)
    .data(erc20Contract.transfer('to address', ethereum.etherToWei('0.01'))) // 0.01 LINK
    .nonce(1) // optional: nonce will be taken from the connected node when not specified
    .sign(wallet.account(0))
    .build();

Sign transaction (transfer NFT)

import 'package:web3_cloud_sdk/client_sdk.dart' as clientsdk;
import 'package:web3_cloud_sdk/ethereum_lib.dart' as ethereum;

// erc721 contract
final erc721Contract = ethereum.Erc721Contract('erc721 contract address');

final signedTx = await ethereum.TxBuilder()
  .value('0')
  .gasPrice('80000000000') // 80 Gwei
  .gasLimit(250000)
  .to(ethereum.Erc721ContractAddress.test)
  .chainId(clientsdk.ChainId.ethereumGoerli)
  .data(erc721Contract.safeTransferFrom('from addresss', 'to address', 1))
  .nonce(1) // optional: nonce will be taken from the connected node when not specified
  .sign(wallet.account(0))
  .build();

Send transaction

final txHash = await wallet.web3.sendTransaction(signedTx);