eos

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: 6 Imported by: 0

README

eos-sdk

EOS SDK is used to interact with the EOS blockchain, it contains various functions can be used to web3 wallet. The SDK not only support EOS, it also supports other blockchain forking from EOS such as WAX.

  • EOS
  • REX
  • TNT
  • WAX

Installation

go get

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

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

Usage

Supported Functions
// NewAccount
// NewTransaction & SignTransaction
// NewContractTransaction & SignTransaction
New Account
	userName := "test3"
	if len(userName) > 12 {
		return
	}
	gotPrivKey, _ := GenerateKeyPair()
	p, err := ecc.NewPrivateKey(gotPrivKey)
	if err != nil {
        // todo
		fmt.Println(err)
	}
	creator := "eosio"
	ram := uint32(1000000)
	cpu := uint64(1000000)
	net := uint64(1000000)
	actions := []*types.Action{
		types.NewNewAccount(creator, userName, p.PublicKey()),
		types.NewBuyRAMBytes(creator, userName, ram),
		types.NewDelegateBW(
			creator,
			userName,
			types.NewEOSAsset(int64(cpu*10000)),
			types.NewEOSAsset(int64(net*10000)),
			false,
		),
	}
	chainId := []byte("e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473")
	opts := &types.TxOptions{
		ChainID: chainId,
	}
	tx := NewTransaction(actions, opts)
	if tx != nil {
		// sign the transaction
		signedTx, packedTx, err := SignTransaction(gotPrivKey, tx, chainId, types.CompressionNone)
        if err != nil {
            // todo
		    fmt.Println(err)
	    }
	}
New Transaction and Sign
	privateKey, err := ecc.NewPrivateKey("5JvW9FSHci6MQcnoHjNnfv5T4Pfi5pj2weAEFQvq1TFaxs8Kbnt")
	opt, err = getTxOptions()
	if err != nil {
        // todo
	}
	tx := NewTransactionWithParams("dubuqing1111", "dubuqing1234", "test", types.NewWAXAsset(500000000), opt)
	DumpGetRequiredKeyContent(tx, privateKey.PublicKey().String(), t)
	signedTx, packedTx, err := SignTransaction(p1, tx, opt.ChainID, types.CompressionNone)
	DumpPackedTx(t, packedTx)
New Contract Transaction and Sign
	privateKey, _ := ecc.NewPrivateKey("5JvW9FSHci6MQcnoHjNnfv5T4Pfi5pj2weAEFQvq1TFaxs8Kbnt")
	opt, err := getTxOptions()
	if err != nil {
        // todo
	}
	contractName := "wax.token"
	tx := NewContractTransaction(contractName, "dubuqing1111", "dubuqing1234", "test", types.NewWAXAsset(500000000), opt)
	DumpGetRequiredKeyContent(tx, privateKey.PublicKey().String(), t)
	signedTx, packedTx, err := SignTransaction(p1, tx, opt.ChainID, types.CompressionNone)
	if err != nil {
        // todo
	}	
	DumpPackedTx(t, packedTx)

License

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKeyPair

func GenerateKeyPair() (privKey, pubKey string)

func HexToChecksum256

func HexToChecksum256(data string) types.Checksum256

func HexToHexBytes

func HexToHexBytes(data string) types.HexBytes

func NewAccountTransaction

func NewAccountTransaction(creator, newAccount string, pubKey ecc.PublicKey, buyRAMAmount, cpuStake, netStake types.Asset,
	doTransfer bool, opts *types.TxOptions) *types.Transaction

NewAccountTransaction creates a new account

func NewBuyRAMBytesTransaction

func NewBuyRAMBytesTransaction(from, to string, bytes uint64, opts *types.TxOptions) *types.Transaction

NewBuyRAMBytesTransaction creates a new EOS BuyRAMBytes transaction.

func NewBuyRamTransaction

func NewBuyRamTransaction(from, to string, quantity types.Asset, opts *types.TxOptions) *types.Transaction

func NewContractTransaction

func NewContractTransaction(name, from, to, memo string, quantity types.Asset, opts *types.TxOptions) *types.Transaction

func NewDelegateBWTransaction

func NewDelegateBWTransaction(from, to string, stakeCPU, stakeNet types.Asset, doTransfer bool,
	opts *types.TxOptions) *types.Transaction

NewDelegateBWTransaction creates a new EOS DelegateBW transaction.

func NewSellRAMTransaction

func NewSellRAMTransaction(account string, bytes uint64, opts *types.TxOptions) *types.Transaction

NewSellRAMTransaction creates a new EOS SellRAM transaction.

func NewTransaction

func NewTransaction(actions []*types.Action, opts *types.TxOptions) *types.Transaction

NewTransaction creates a new EOS Transaction object, ready to sign.

func NewTransactionWithParams

func NewTransactionWithParams(from, to, memo string, quantity types.Asset, opts *types.TxOptions) *types.Transaction

func NewUndelegateBWTransaction

func NewUndelegateBWTransaction(from, to string, unstakeCPU, unstakeNet types.Asset, opts *types.TxOptions) *types.Transaction

NewUndelegateBWTransaction creates a new EOS UndelegateBW transaction.

func SigDigest

func SigDigest(chainID, payload, contextFreeData []byte) []byte

SigDigest computes the hash of the packed transaction

func SignTransaction

func SignTransaction(wifKey string, tx *types.Transaction, chainID types.Checksum256,
	compression types.CompressionType) (*types.SignedTransaction, *types.PackedTransaction, error)

SignTransaction signs a transaction with the given WIF.

func SignTransactionWithWIFs

func SignTransactionWithWIFs(wifs []string, tx *types.Transaction, chainID types.Checksum256,
	compression types.CompressionType) (*types.SignedTransaction, *types.PackedTransaction, error)

SignTransactionWithWIFs signs a transaction with the given WIFs.

Types

type Signer

type Signer struct {
	Keys []*ecc.PrivateKey `json:"keys"`
}

func NewSigner

func NewSigner(keys []*ecc.PrivateKey) *Signer

func NewSignerFromWIFs

func NewSignerFromWIFs(wifs []string) (*Signer, error)

func (*Signer) Add

func (b *Signer) Add(wifKey string) error

func (*Signer) Sign

func (b *Signer) Sign(tx *types.SignedTransaction, chainID []byte, requiredKeys ...ecc.PublicKey) (*types.SignedTransaction, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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