MCPcopy Index your code
hub / github.com/coming-chat/wallet-SDK

github.com/coming-chat/wallet-SDK @v55.66.88

Chat with this repo
repository ↗ · DeepWiki ↗ · release v55.66.88 ↗ · + Follow
628 symbols 1,690 edges 102 files 251 documented · 40% 6 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

wallet-SDK

Bitcoin Ethereum Polka Cosmos
import mnemonic
import keystore
pri/pub key & address
multi network
publicKey to address
address to publicKey
sign data ☑️ ☑️ ☑️
query balance
fetch transaction detail
gas fee ☑️
send taw transaction ✅ ☑️ ✅ ☑️
multi token ✅ erc20 ✅ XBTC

If there are two icons, the first icon indicates development status, and the second icon indicates test status. ✅: Completed ☑️: TODO ❌: Unsupported

Usage

About Wallet

SDK provide wallet import, account public and private key and address acquisition.

Import Wallet

// import mnemonic
wallet, err = NewWalletFromMnemonic(mnemonic)

// import keystore
// It only supports Polka keystore.
wallet, err = NewWalletFromKeyStore(keyStoreJson, password)

Create Account

We currently support accounts in Bitcoin, Ethereum and Polkadot ecosystems.

// Polka
polkaAccount, err = wallet.GetOrCreatePolkaAccount(network)

// Bitcoin
bitcoinAccount, err = wallet.GetOrCreateBitcoinAccount(chainnet)

// Ethereum
ethereumAccount, err = wallet.GetOrCreateEthereumAccount()

// Cosmos
cosmosAccount, err = wallet.GetOrCreateCosmosAccount()

// Terra is a type of cosmos
terraAccount, err = wallet.GetOrCreateCosmosTypeAccount(330, "terra")

Get PrivateKey, PublicKey, Address

privateData, err = account.PrivateKeyData()

privateKey, err = account.PrivateKey()

publicKey = account.PublicKey()

address = account.Address()

About Chain

We can use chain tools to do chain related work. * query balance * query estimate fees * send transaction * fetch transaction detail * support multi token: * eth contract erc20 token * xbtc

Create Chain

polkaChain, err = polka.NewChainWithRpc(rpcUrl, scanUrl, network)

bitcoinChain, err = btc.NewChainWithChainnet(chainnet)

ethereumChain, err = eth.NewChainWithRpc(rpcUrl)

cosmosChain, err = cosmos.NewChainWithRpc(rpcUrl, restUrl)
terraChain, err = cosmos.NewChainWithRpc(terraRpcUrl, terraRestUrl)

Methods


// query balance
balance, err = chain.BalanceOfAddress(address)
balance, err = chain.BalanceOfPublicKey(publicKey)
balance, err = chain.BalanceOfAccount(account)

// send transaction
txHash, err = chain.SendRawTransaction(signedTx)

// fetch transaction detail
detail, err = chain.FetchTransactionDetail(hashString)
status = chain.FetchTransactionStatus(hashString)

Chain's Token

// MainToken
token = chain.MainToken()

// btc have not tokens

// polka (only support XBTC of ChainX currently)
xbtcToken = polkaChain.XBTCToken()

// ethereum erc20 token
erc20Token = ethereumChain.Erc20Token(contractAddress)

// cosmos token
atomToken = cosmosChain.DenomToken("cosmos", "uatom")
ustToken = terraChain.DenomToken("terra", "uusd")

// token balance (similar to chain's balance)
balance, err = anyToken.BalanceOfAddress(address)
balance, err = anyToken.BalanceOfPublicKey(publicKey)
balance, err = anyToken.BalanceOfAccount(account)

Estimate fee

// sbtc's estimate fee is compute by utxo

// polka 
transaction = // ...
fee, err = polkaChain.EstimateFeeForTransaction(transaction)

// ethereum
gasPrice, err = ethChain.SuggestGasPrice()
gasLimit, err = anyEthToken.EstimateGasLimit(fromAddress, receiverAddress, gasPrice, amount)

--------------------------------------------------------------------------------

Cosmos & Terra Demo

Creator

// Import mnemonic
wallet, err = NewWalletFromMnemonic(mnemonic)

// Cosmos account
cosmosAccount, err = wallet.GetOrCreateCosmosAccount()
// Terra is a type of cosmos
terraAccount, err = wallet.GetOrCreateCosmosTypeAccount(330, "terra")

// Create Chain
chain, err = cosmos.NewChainWithRpc(rpcUrl, restUrl)

// Create a coin token
atomToken = cosmosChain.DenomToken("cosmos", "uatom")
lunaToken = terraChain.DenomToken("terra", "uluna")
ustToken = terraChain.DenomToken("terra", "uusd")

Query balance

// query balance with token
atomBalance, err = atomToken.BalanceOfAddress("cosmos1lkw6n8efpj7mk29yvajpn9zue099l359cgzf0t")
lunaBalance, err = lunaToken.BalanceOfAddress("terra1ncjg4a59x2pgvqy9qjyqprlj8lrwshm0wleht5")
ustBalance , err =  ustToken.BalanceOfAddress("terra1dr7ackrxsqwmac2arx26gre6rj6q3sv29fnn7k")

// you can query balance with chain directly
atomBalance, err = cosmosChain.BalanceOfAddressAndDenom("cosmos1lkw6n8efpj7mk29yvajpn9zue099l359cgzf0t", "uatom") // uatom
lunaBalance, err =  terraChain.BalanceOfAddressAndDenom("terra1ncjg4a59x2pgvqy9qjyqprlj8lrwshm0wleht5", "uluna")  // uluna
ustBalance , err =  terraChain.BalanceOfAddressAndDenom("terra1dr7ackrxsqwmac2arx26gre6rj6q3sv29fnn7k", "uusd")   // uusd

Fetch Transaction Detail

atomDetail, err = cosmosChain.FetchTransactionDetail("F068275DE4A4CC904D3E6A412A50DFACC235C62770BCD001E54E00BC4C17B1F0")

lunaDetail, err =  terraChain.FetchTransactionDetail("19771A22934641DBD3D347DCCAE939DAC37F39ABD88005AA735B8AAEA78599BA")

// exactly the same as luna detail.
ustDetail , err =  terraChain.FetchTransactionDetail("25ACF16526D3A4DEE5FE7C5CCEB597B5691134647829AD30CA1E36EDBEAC32B6")

Sign & Send transaction

cosmosAccount = // create a cosmos account
toAddress = "cosmos1lkw6n8efpj7mk29yvajp......"
amount = "100000"
gasPrice = "0.01"
gasLimit = "80000"

chain = cosmos.NewChainWithRpc(rpcUrl, restUrl)
token = chain.DenomToken(prefix, denom)

signedTx, err = token.BuildTransferTx(account.PrivateKeyHex(), toAddress, gasPrice, gasLimit, amount)

txHash, err = chain.SendRawTransaction(signedTx)

--------------------------------------------------------------------------------

Ethereum Sign Transaction

ethereumChain, err = eth.NewChainWithRpc(rpcUrl)

// make an transaction object
transaction = NewTransaction(nonce, gasPrice, gasLimit, to, value, data)
// transaction.MaxPriorityFeePerGas = "10000" // if send EIP1559 tx

// sign with hexed privatekey
signedTxObj, err = ethereumChain.SignTransaction(privateKeyHex, transaction)
// sign with ethereum account
signedTxObj, err = ethereumChain.SignTransactionWithAccount(ethAccount, transaction) 

signedHashString = signedTxObj.Value // signed transaction hash string

--------------------------------------------------------------------------------

ComingChat substrate wallet SDK

build android && ios

  • make buildAllAndroid
  • make buildAllIOS

Struct

Wallet

Wallet 工具类方法(静态方法)

  • 获取助记词:

java String mnemonicString = Wallet.genMnemonic();

throw err

  • 创建钱包:
  • 从助记词或私钥

    java Wallet wallet = Wallet.newWallet(seedOrPhrase);

    参数 类型 描述 获取方式
    seedOrPhrase string 助记词或者私钥
    network int ss58

    throw err

  • 从keystore

    java Wallet wallet = Wallet.NewWalletFromKeyStore(keyStoreJson, password);

    参数 类型 描述 获取方式
    keyStoreJson string keystore
    password string 密码

    throw err

  • 地址转公钥

java String publicKey = Wallet.addressToPublicKey(address);

参数 类型 描述 获取方式
address string 地址

​ throw err

  • 公钥转地址

    java String address = Wallet.publicKeyToAddress(publicKey, network);

    参数 类型 描述 获取方式
    publicKey string 公钥16进制字符串
    network int ss58

​ throw err

Wallet类方法

  • 获取公钥:

    java String publicKeyHex = wallet.getPublicKeyHex(); byte[] publicKey = wallet.getPublicKey();

  • 获取私钥:

    java String privateKey = wallet.getPrivateKeyHex();

    throw err

  • 签名:

    java byte[] signature = wallet.sign(message, password);

    参数 类型 描述 获取方式
    message []byte 签名内容
    password string keystore 密码,如果是助记词或者私钥创建则随便填

    throw err

  • 检查Keystore密码

    java bool isCorrect = wallet.checkPassword(password);

    参数 类型 描述 获取方式
    password string

throw err

  • 获取地址:

    java String address = wallet.getAddress(network);

    参数 类型 描述 获取方式
    network int ss58

    throw err

Tx

  • 创建Tx

    java Tx tx = Tx.NewTx(metadataString);

    参数 类型 描述 获取方式
    metadataString string metadata的16进制string 接口获取

    throw err

  • 从Hex创建Transaction

    Transaction t = tx.newTransactionFromHex(txHex)

    参数 类型 描述 获取方式
    txHex string tx的16进制数据 从Wallet Connect获取

    throw err

  • 创建Balance转账

    java Transaction t = tx.newBalanceTransferTx(dest, amount);

    参数 类型 描述 获取方式
    dest string 对方address 输入
    amount string 金额 用户输入

    throw err

  • 创建ChainX转账

    java Transaction t = tx.newBalanceTransferTx(dest, amount);

    参数同上

    throw err

  • 创建NFT转账

    java Transaction t = tx.newComingNftTransferTx(dest, cid);

    参数 类型 描述 获取方式
    dest string 对方address 输入
    cid long cid 用户输入

    throw err

  • 创建XBTC转账

    java Transaction t = tx.newXAssetsTransferTx(dest, amount);

    参数同上

    throw err

  • 创建mini门限转账

    java Transaction t = tx.NewThreshold(thresholdPublicKey, destAddress, aggSignature, aggPublicKey, controlBlock, message, scriptHash, transferAmount, blockNumber);

    参数 类型 描述 获取方式
    thresholdPublicKey string 门限钱包公钥 generateThresholdPubkey()
    destAddress string 对方地址
    aggSignature string 聚合签名 getAggSignature()
    aggPublicKey string 聚合公钥 getAggPubkey()
    controlBlock string controlBlock generateControlBlock()
    message string 576520617265206c6567696f6e21 写死
    scriptHash string scriptHash 接口获取
    transferAmount string 转账金额 用户输入
    blockNumber int32 blockNumber 与scriptHash同接口获取

    throw err

Transaction

  • 获取未签名Tx

    java String unSignTx = t.getUnSignTx(); throw err 此方法用于预估矿工费使用

  • 获取需要签名内容

    java byte[] signData = t.getSignData(genesisHashString, nonce, specVersion, transVersion);

    参数 类型 描述 获取方式
    genesisHashString string genesisHash 接口获取
    nonce int64 nonce 接口获取
    specVersion int32 接口获取
    transVersion int32 接口获取

    throw err

  • 获取Tx

    java String sendTx = t.getTx(signerPublicKey, signatureData);

    参数 类型 描述 获取方式
    signerPublicKey byte[] 签名者公钥 获取公钥的getPublicKey方法
    signatureData byte[] 签名结果

    throw err

交易构造流程

  1. 导入助记词或私钥,生成钱包对象

  2. 调用创建钱包获得钱包对象wallet用于签名

  3. 调用接口获取构造参数(nonce, specVersion, transVersion )

  4. Metadata的获取根据接口判断

  5. 调用创建Tx获得tx对象用于构造交易

  6. 通过tx对象创建交易t

  7. 用钱包Sign方法对交易t的内容(获取需要签名内容)签名

  8. 将签名方公钥(获取公钥)和签名内容放入GetTx的方法中

  9. 交易t调用获取Tx获得SendTx

```java try { String mnemonicString = Wallet.genMnemonic(); Wallet wallet = Wallet.newWallet(mnemonicString); Tx tx = Tx.NewTx(metadataString); String dest = "5UczqUVGsoQpZnBCZkDtxvLxJ42KnUfaGTzPkQmZeAAug4s9"; String genesisHashString = "0xfb58f83706a065ced8f658fafaba97e6e49b772287e332077c499784184eda9f"; long amount = "100

Extension points exported contracts — how you extend this code

AddressUtil (Interface)
(no doc) [6 implementers]
core/base/account.go
Jsonable (Interface)
支持 对象 和 json 字符串 相互转换
core/eth/ethchain_transactionDetail.go
Account (Interface)
(no doc) [4 implementers]
core/base/account.go
TokenProtocol (Interface)
(no doc) [2 implementers]
core/eth/token.go
Chain (Interface)
(no doc) [4 implementers]
core/base/chain.go
Token (Interface)
(no doc) [4 implementers]
core/base/token.go

Core symbols most depended-on inside this repo

Decode
called by 22
core/substrate/types/customscale/argType.go
Address
called by 18
core/base/account.go
GetConnection
called by 18
core/eth/chainManager.go
Chain
called by 17
core/base/token.go
CatchPanicAndMapToBasicError
called by 16
core/base/util.go
MapAnyToBasicError
called by 15
core/base/util.go
Decode
called by 13
core/substrate/types/map.go
Sign
called by 10
core/base/account.go

Shape

Method 294
Function 248
Struct 75
Interface 6
TypeAlias 4
FuncType 1

Languages

Go100%

Modules by API surface

core/eth/types.go29 symbols
util/mathutil/mathutil.go20 symbols
crypto/crypto.go17 symbols
core/wallet/wallet.go15 symbols
core/polka/transaction.go15 symbols
core/polka/account.go15 symbols
core/eth/token.go15 symbols
core/eth/coin.go14 symbols
core/cosmos/chain.go13 symbols
core/btc/account.go13 symbols
core/polka/chain.go12 symbols
core/eth/chain.go12 symbols

For agents

$ claude mcp add wallet-SDK \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact