zksync

package module
v0.0.0-...-61460eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 4 Imported by: 0

README

zksync-sdk

Zksync SDK is used to interact with the Zksync blockchain, it contains various functions can be used to web3 wallet.

Installation

go get

To obtain the latest version, simply require the project using :

go get -u github.com/okx/go-wallet-sdk/coins/zksync

Usage

New address
privKeyBytes, _ := hex.DecodeString("559376194bb4c9a9dfb33fde4a2ab15daa8a899a3f43dee787046f57d5f7b10a")
ethSigner, err := core.NewOkEthSignerFromPrivBytes(privKeyBytes)
zkSigner, err := core.NewZkSignerFromEthSigner(ethSigner, core.ChainIdRinkeby)

Create withdraw transaction
accountId := uint32(1291712)
addr := "0x0bc4b0c3483084bb71614e114968c1a0ae588888"
amount := big.NewInt(12312124)
fee := big.NewInt(10000)
feeToken := RinkebyUSDC
nonce := uint32(20)
validFrom := uint64(0)
validUntil := uint64(10000000000000000)
tx := CreateWithdrawTx(accountId, addr, amount, fee, feeToken, nonce, validFrom, validUntil)

signedTx, err := SignWithdraw(tx, token, ethPrivKeyHex, int(core.ChainIdRinkeby))
Create transfer transaction
accountId := uint32(1291712)
from := "0x0bc4b0c3483084bb71614e114968c1a0ae588888"
addr := "0x0bc4b0c3483084bb71614e114968c1a0ae588888"
amount := big.NewInt(12312124)
fee := big.NewInt(10000)
feeToken := RinkebyUSDC
nonce := uint32(20)
validFrom := uint64(0)
validUntil := uint64(10000000000000000)
tx := CreateTransferTx(accountId, from, addr, amount, fee, feeToken, nonce, validFrom, validUntil)

signedTx, err := SignTransfer(tx, ethPrivKeyHex, int(core.ChainIdRinkeby))
Create transfer with fee token transaction
accountId := uint32(1291712)
from := "0x0bc4b0c3483084bb71614e114968c1a0ae588888"
to := "0x0e81575BF66e79915A22c614e2046d360e40a3f9"
amount := big.NewInt(12312124)
fee := big.NewInt(10000)
feeToken := RinkebyUSDC
nonce := uint32(18)
validFrom := uint64(0)
validUntil := uint64(10000000000000000)
txs := CreateTransferWithFeeTokenTx(accountId, from, to, amount, feeToken, fee, RinkebyUSDT, nonce, validFrom, validUntil)

signedTx, err := SignBatchTransfer(txs, ethPrivKeyHex, int(core.ChainIdRinkeby))
Create change pubkey transaction
ethPrivKeyHex := "559376194bb4c9a9dfb33fde4a2ab15daa8a899a3f43dee787046f57d5f7b10a"
accountId := uint32(1291712)
address, _ := GetAddress(ethPrivKeyHex)
pubKeyHash, _ := GetPubKeyHash(ethPrivKeyHex, int(core.ChainIdRinkeby))
token := RinkebyUSDC
fee := big.NewInt(100000000000000)
nonce := uint32(2)
validFrom := uint64(0)
validUntil := uint64(4294967295)
tx := CreateChangePubKeyTx(accountId, address, pubKeyHash, token, fee, nonce, validFrom, validUntil)

signedTx, err := SignChangePubKey(tx, ethPrivKeyHex, int(core.ChainIdRinkeby))
Create mint nft transaction
ethPrivKeyHex := "559376194bb4c9a9dfb33fde4a2ab15daa8a899a3f43dee787046f57d5f7b10a"
accountId := uint32(1291712)
address, _ := GetAddress(ethPrivKeyHex)
token := RinkebyUSDC
fee := big.NewInt(100000000000000)
nonce := uint32(29)
NFTContentHash := "1"
tx := CreateMintNFTTx(accountId, address, address, NFTContentHash, token, fee, nonce)

signedTx, err := SignMintNFT(tx, feeToken, ethPrivKeyHex, int(core.ChainIdRinkeby))
Create transfer nft transaction
ethPrivKeyHex := "559376194bb4c9a9dfb33fde4a2ab15daa8a899a3f43dee787046f57d5f7b10a"
toAddress := "0x0e81575BF66e79915A22c614e2046d360e40a3f9"
accountId := uint32(1291712)
address, _ := GetAddress(ethPrivKeyHex)
token := RinkebyUSDC
fee := big.NewInt(100000000000000)
nonce := uint32(16)
nftSymbol := "NFT-113561"
validFrom := uint64(0)
validUntil := uint64(10000000000000000)
transfers, err := CreateTransferNFTTx(accountId, address, toAddress, nftSymbol, token, fee, nonce, validFrom, validUntil)

signedTx, err := SignBatchTransfer(txs, ethPrivKeyHex, int(core.ChainIdRinkeby))
Create withdraw nft transaction
ethPrivKeyHex := "559376194bb4c9a9dfb33fde4a2ab15daa8a899a3f43dee787046f57d5f7b10a"
accountId := uint32(1291712)
address, _ := GetAddress(ethPrivKeyHex)
token := RinkebyUSDC
fee := big.NewInt(100000000000000)
nonce := uint32(16)
nftId := uint32(113561)
validFrom := uint64(0)
validUntil := uint64(10000000000000000)
tx := CreateWithdrawNFTTx(accountId, address, nftId, token, fee, nonce, validFrom, validUntil)

signedTx, err := SignWithdrawNFT(tx, feeToken, ethPrivKeyHex, int(core.ChainIdRinkeby))

License

Most packages or folder are MIT licensed, see package or folder for the respective license.

Documentation

Index

Constants

View Source
const (
	WITHDRAW       = "Withdraw"
	TRANSFER       = "Transfer"
	CHANGE_PUB_KEY = "ChangePubKey"
	MINT_NFT       = "MintNFT"
	WITHDRAW_NFT   = "WithdrawNFT"
)
View Source
const UINT32_MAX = ^uint32(0)

Variables

View Source
var ETH = core.CreateETH()
View Source
var RinkebyUSDC = &core.Token{
	Id:       2,
	Address:  "0xeb8f08a975ab53e34d8a0330e0d34de942c95926",
	Symbol:   "USDC",
	Decimals: 6,
	IsNft:    false,
}
View Source
var RinkebyUSDT = &core.Token{
	Id:       1,
	Address:  "0x3b00ef435fa4fcff5c209a37d1f3dcff37c705ad",
	Symbol:   "USDT",
	Decimals: 6,
	IsNft:    false,
}
View Source
var USDT = &core.Token{
	Id:       4,
	Address:  "0xdac17f958d2ee523a2206206994597c13d831ec7",
	Symbol:   "USDT",
	Decimals: 6,
	IsNft:    false,
}

Functions

func CreateChangePubKeyTx

func CreateChangePubKeyTx(accountId uint32, fromAddress, pubKeyHash string, feeToken *core.Token, fee *big.Int, nonce uint32, validFrom, validUntil uint64) *core.ChangePubKey

func CreateMintNFTTx

func CreateMintNFTTx(accountId uint32, creator, recipient, contentHash string, feeToken *core.Token, fee *big.Int, nonce uint32) *core.MintNFT

func CreateTransferNFTTx

func CreateTransferNFTTx(accountId uint32, fromAddress, toAddress, nftSymbol string, feeToken *core.Token, fee *big.Int, nonce uint32, validFrom, validUntil uint64) ([]*core.Transfer, error)

func CreateTransferTx

func CreateTransferTx(accountId uint32, fromAddress, toAddress string, amount *big.Int, fee *big.Int, token *core.Token, nonce uint32, validFrom, validUntil uint64) *core.Transfer

func CreateTransferWithFeeTokenTx

func CreateTransferWithFeeTokenTx(accountId uint32, fromAddress, toAddress string, amount *big.Int, token *core.Token, fee *big.Int, feeToken *core.Token, nonce uint32, validFrom, validUntil uint64) []*core.Transfer

func CreateWithdrawNFTTx

func CreateWithdrawNFTTx(accountId uint32, addr string, nftId uint32, feeToken *core.Token, fee *big.Int, nonce uint32, validFrom, validUntil uint64) *core.WithdrawNFT

func CreateWithdrawTx

func CreateWithdrawTx(accountId uint32, address string, amount *big.Int, fee *big.Int, token *core.Token, nonce uint32, validFrom, validUntil uint64) *core.Withdraw

func GetAddress

func GetAddress(ethPrivKeyHex string) (string, error)

func GetPubKeyHash

func GetPubKeyHash(ethPrivKeyHex string, chainId int) (string, error)

func SignChangePubKey

func SignChangePubKey(changePubKey *core.ChangePubKey, ethPrivKeyHex string, chainId int) (*core.SignedTransaction, error)

func SignMintNFT

func SignMintNFT(mintNFT *core.MintNFT, feeToken *core.Token, ethPrivKeyHex string, chainId int) (*core.SignedTransaction, error)

func SignTransfer

func SignTransfer(transfer *core.Transfer, ethPrivKeyHex string, chainId int) (*core.SignedTransaction, error)

func SignWithdraw

func SignWithdraw(withdraw *core.Withdraw, feeToken *core.Token, ethPrivKeyHex string, chainId int) (*core.SignedTransaction, error)

func SignWithdrawNFT

func SignWithdrawNFT(withdrawNft *core.WithdrawNFT, feeToken *core.Token, ethPrivKeyHex string, chainId int) (*core.SignedTransaction, error)

Types

type BatchTransaction

type BatchTransaction struct {
	Txs       []core.SignedTransaction `json:"txs"`
	Signature *core.EthSignature       `json:"signature"`
}

func SignBatchTransfer

func SignBatchTransfer(transfers []*core.Transfer, ethPrivKeyHex string, chainId int) (*BatchTransaction, error)

Directories

Path Synopsis
* The MIT License (MIT)
* The MIT License (MIT)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL