Documentation ¶
Index ¶
- type Block
- type Client
- func (c Client) BlockByNumber(blockNumber *big.Int) (*Block, error)
- func (c Client) Close()
- func (c Client) CurrentBlockNumber() (number uint64, err error)
- func (c Client) CurrentChainId() (*big.Int, error)
- func (c Client) DeployContract(abi, byteCode io.Reader, chainId *big.Int, privateKey string) (*Contract, *Transaction, error)
- func (c Client) NewBoundContract(abi io.Reader, address string) (*Contract, error)
- type Contract
- type ContractMethod
- type Transaction
- func (t *Transaction) Chain() (*big.Int, error)
- func (t *Transaction) Data() ([]byte, error)
- func (t *Transaction) Gas() (uint64, error)
- func (t *Transaction) GasFeeCap() (*big.Int, error)
- func (t *Transaction) GasPrice() (*big.Int, error)
- func (t *Transaction) GasTipCap() (*big.Int, error)
- func (t *Transaction) Hash() ([]byte, error)
- func (t *Transaction) Nonce() (uint64, error)
- func (t *Transaction) RawSignatures() (rawSignatures, error)
- func (t *Transaction) Send() (err error)
- func (t *Transaction) ToAddress() ([]byte, error)
- func (t *Transaction) Value() (*big.Int, error)
Examples ¶
- Block.NonceFromPrivateKey
- Block.Number
- Block.Transaction
- Block.Transactions
- Client.BlockByNumber
- Client.CurrentBlockNumber
- Client.CurrentChainId
- Client.DeployContract
- Client.NewBoundContract
- Contract.Method
- Contract.Methods
- ContractMethod.Call
- ContractMethod.Transact
- New
- Transaction.Chain
- Transaction.Data
- Transaction.Gas
- Transaction.GasFeeCap
- Transaction.GasPrice
- Transaction.GasTipCap
- Transaction.Hash
- Transaction.Nonce
- Transaction.RawSignatures
- Transaction.Send
- Transaction.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
Block defines wrappers for a block retrieved by the client.
func (*Block) NonceFromPrivateKey ¶
NonceFromPrivateKey returns the account nonce of the account given from the secp256k1 hexkey. The block number can be nil, in which case the nonce is taken from the latest known block.
Example ¶
package main import ( "fmt" "math/big" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockNumber: big.NewInt(20), BlockNonce: 6, } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } nonce, err := block.NonceFromPrivateKey("HexKey") if err != nil { return } fmt.Printf("%d\n", nonce) }
Output: 6
func (*Block) Number ¶
Number returns the *big.Int value of the block number
Example ¶
package main import ( "fmt" "math/big" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockNumber: big.NewInt(20), } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } blockNumber, err := block.Number() if err != nil { return } fmt.Printf("%d\n", blockNumber) }
Output: 20
func (*Block) Transaction ¶
func (b *Block) Transaction(hash []byte) (*Transaction, error)
Transaction returns transaction from block with the given transaction hash.
Transaction hash is 32 bytes, if inputted hash is longer than 32 bytes hash will be trimmed.
Example ¶
package main import ( "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) var tx *ethereum.Transaction func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockTransaction: 6, } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } // Mocking transaction hash txHash := make([]byte, 32) _, err = rand.Read(txHash) if err != nil { return } tx, err = block.Transaction(txHash) if err != nil { return } fmt.Println("success") }
Output: success
func (*Block) Transactions ¶
func (b *Block) Transactions() ([]*Transaction, error)
Transactions returns all transactions from the given block.
Example ¶
package main import ( "fmt" "math/big" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockTransactions: []uint32{1, 2, 3}, } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } txs, err := block.Transactions() if err != nil { return } fmt.Println(len(txs)) }
Output: 3
type Client ¶
type Client uint32
Client defines typed wrappers for the Ethereum RPC API.
func New ¶
New connects a client to the given rpc URL.
Example ¶
package main import ( "fmt" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 5, } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } fmt.Printf("%d\n", client) }
Output: 5
func (Client) BlockByNumber ¶
BlockByNumber returns a block from the current canonical chain. If number is nil, the latest known block is returned.
Example ¶
package main import ( "fmt" "math/big" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) var block *ethereum.Block func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err = client.BlockByNumber(big.NewInt(20)) if err != nil { return } fmt.Println("success") }
Output: success
func (Client) CurrentBlockNumber ¶
CurrentBlockNumber returns the most recent block number.
Example ¶
package main import ( "fmt" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, CurrentBlockNumber: 5, } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } blockNumber, err := client.CurrentBlockNumber() if err != nil { return } fmt.Printf("%d\n", blockNumber) }
Output: 5
func (Client) CurrentChainId ¶
CurrentChainID retrieves the current chain ID for transaction replay protection.
Example ¶
package main import ( "fmt" "math/big" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, CurrentChainId: big.NewInt(5), } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } chainId, err := client.CurrentChainId() if err != nil { return } fmt.Printf("%d\n", chainId) }
Output: 5
func (Client) DeployContract ¶ added in v0.1.37
func (c Client) DeployContract(abi, byteCode io.Reader, chainId *big.Int, privateKey string) (*Contract, *Transaction, error)
DeployContract method deploys the contract on given chain,returns low level contract interface through which calls and transactions may be made through.
Example ¶
// Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, ContractAddress: "address", Contract: map[string]ethereumSym.MockContractMethod{ "fakeMethod": { Inputs: []interface{}{big.NewInt(5)}, Outputs: []interface{}{big.NewInt(6)}, }, }, ContractTransactionId: 2, ContractId: 3, } mockData.Mock() // Creates new client from given RPC url, this is not a real rpc url. client, err := ethereum.New("https://testRPC.url") if err != nil { return } // Mocking abi data abiRawData := make([]byte, 1024) rand.Read(abiRawData) // Mocking byte code byteCodeData := make([]byte, 1024) rand.Read(byteCodeData) chainId := big.NewInt(5) contract, tx, err = client.DeployContract(bytes.NewReader(abiRawData), bytes.NewReader(byteCodeData), chainId, "private key") if err != nil { return } fmt.Println("success")
Output: success
func (Client) NewBoundContract ¶
NewBoundContract method creates a low level contract interface through which calls and transactions may be made through.
Example ¶
package main import ( "bytes" "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) var contract *ethereum.Contract func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, ContractAddress: "address", Contract: map[string]ethereumSym.MockContractMethod{ "fakeMethod": { Inputs: []interface{}{big.NewInt(5)}, Outputs: []interface{}{big.NewInt(6)}, }, }, ContractTransactionId: 2, ContractId: 3, } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } // Mocking abi data abiRawData := make([]byte, 1024) rand.Read(abiRawData) contract, err = client.NewBoundContract(bytes.NewReader(abiRawData), "address") if err != nil { return } fmt.Println("success") }
Output: success
type Contract ¶
type Contract struct {
// contains filtered or unexported fields
}
Contract defines typed wrappers for a contract with given abi.
func (*Contract) Method ¶
func (c *Contract) Method(name string) (*ContractMethod, error)
Method returns the contract method with the corresponding inputted name.
Example ¶
package main import ( "bytes" "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, ContractAddress: "address", Contract: map[string]ethereumSym.MockContractMethod{ "fakeMethod": { Inputs: []interface{}{big.NewInt(5)}, Outputs: []interface{}{big.NewInt(6)}, }, }, ContractTransactionId: 2, ContractId: 3, } mockData.Mock() // Creates new client from given RPC url, this is not a real rpc url. client, err := ethereum.New("https://testRPC.url") if err != nil { return } // Mocking abi data abiRawData := make([]byte, 1024) rand.Read(abiRawData) contract, err := client.NewBoundContract(bytes.NewReader(abiRawData), "address") if err != nil { return } fakeMethod, err := contract.Method("fakeMethod") if err != nil { return } fmt.Println(fakeMethod.Name()) }
Output: fakeMethod
func (*Contract) Methods ¶
func (c *Contract) Methods() []*ContractMethod
Methods lists the available methods for within the given contract
Example ¶
package main import ( "bytes" "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, ContractAddress: "address", Contract: map[string]ethereumSym.MockContractMethod{ "fakeMethod": { Inputs: []interface{}{big.NewInt(5)}, Outputs: []interface{}{big.NewInt(6)}, }, }, ContractTransactionId: 2, ContractId: 3, } mockData.Mock() // Creates new client from given RPC url, this is not a real rpc url. client, err := ethereum.New("https://testRPC.url") if err != nil { return } // Mocking abi data abiRawData := make([]byte, 1024) rand.Read(abiRawData) contract, err := client.NewBoundContract(bytes.NewReader(abiRawData), "address") if err != nil { return } fmt.Println(len(contract.Methods())) }
Output: 1
type ContractMethod ¶
type ContractMethod struct {
// contains filtered or unexported fields
}
func (*ContractMethod) Call ¶
func (c *ContractMethod) Call(inputParameters ...interface{}) ([]interface{}, error)
Call invokes the (constant) contract method with params as input values
Example ¶
package main import ( "bytes" "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, ContractAddress: "address", Contract: map[string]ethereumSym.MockContractMethod{ "fakeMethod": { Inputs: []interface{}{big.NewInt(5)}, Outputs: []interface{}{big.NewInt(6)}, }, }, ContractTransactionId: 2, ContractId: 3, } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } // Mocking abi data abiRawData := make([]byte, 1024) rand.Read(abiRawData) contract, err := client.NewBoundContract(bytes.NewReader(abiRawData), "address") if err != nil { return } fakeMethod, err := contract.Method("fakeMethod") if err != nil { return } outputs, err := fakeMethod.Call(big.NewInt(5)) if err != nil || len(outputs) != 1 { return } fmt.Println(outputs[0]) }
Output: 6
func (*ContractMethod) Name ¶
func (c *ContractMethod) Name() string
func (*ContractMethod) Transact ¶
func (c *ContractMethod) Transact(chainId *big.Int, privateKey string, inputParameters ...interface{}) (*Transaction, error)
Transact invokes the (paid) contract method with params as input values. If chain id is nil, then current chain Id is used.
Example ¶
// Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, ContractAddress: "address", Contract: map[string]ethereumSym.MockContractMethod{ "fakeMethod": { Inputs: []interface{}{big.NewInt(5)}, Outputs: []interface{}{big.NewInt(6)}, }, }, ContractTransactionId: 2, ContractId: 3, } mockData.Mock() // Creates new client from given RPC url, this is not a real rpc url. client, err := ethereum.New("https://testRPC.url") if err != nil { return } // Mocking abi data abiRawData := make([]byte, 1024) rand.Read(abiRawData) contract, err := client.NewBoundContract(bytes.NewReader(abiRawData), "address") if err != nil { return } fakeMethod, err := contract.Method("fakeMethod") if err != nil { return } chainId := big.NewInt(10) tx, err = fakeMethod.Transact(chainId, "privateKey", big.NewInt(5)) if err != nil { return } fmt.Println("success")
Output: success
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction defines wrappers for a transaction retrieved by the client.
func (*Transaction) Chain ¶
func (t *Transaction) Chain() (*big.Int, error)
Chain returns the EIP155 chain ID of the transaction. The return value will always be non-nil. For legacy transactions which are not replay-protected, the return value is zero.
Example ¶
package main import ( "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockTransaction: 6, TransactionBytes: big.NewInt(7).Bytes(), } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } // Mocking transaction hash txHash := make([]byte, 32) _, err = rand.Read(txHash) if err != nil { return } tx, err := block.Transaction(txHash) if err != nil { return } chain, err := tx.Chain() if err != nil { return } fmt.Println(chain) }
Output: 7
func (*Transaction) Data ¶
func (t *Transaction) Data() ([]byte, error)
Data returns the input data of the transaction.
Example ¶
package main import ( "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockTransaction: 6, TransactionBytes: []byte("Hello World"), } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } // Mocking transaction hash txHash := make([]byte, 32) _, err = rand.Read(txHash) if err != nil { return } tx, err := block.Transaction(txHash) if err != nil { return } data, err := tx.Data() if err != nil { return } fmt.Println(string(data)) }
Output: Hello World
func (*Transaction) Gas ¶
func (t *Transaction) Gas() (uint64, error)
Gas returns the gas limit of the transaction.
Example ¶
package main import ( "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockTransaction: 6, TransactionU64: 7, } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } // Mocking transaction hash txHash := make([]byte, 32) _, err = rand.Read(txHash) if err != nil { return } tx, err := block.Transaction(txHash) if err != nil { return } gas, err := tx.Gas() if err != nil { return } fmt.Println(gas) }
Output: 7
func (*Transaction) GasFeeCap ¶
func (t *Transaction) GasFeeCap() (*big.Int, error)
GasFeeCap returns the fee cap per gas of the transaction.
Example ¶
package main import ( "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockTransaction: 6, TransactionBytes: big.NewInt(7).Bytes(), } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } // Mocking transaction hash txHash := make([]byte, 32) _, err = rand.Read(txHash) if err != nil { return } tx, err := block.Transaction(txHash) if err != nil { return } gasFeeCap, err := tx.GasFeeCap() if err != nil { return } fmt.Println(gasFeeCap) }
Output: 7
func (*Transaction) GasPrice ¶
func (t *Transaction) GasPrice() (*big.Int, error)
GasPrice returns the gas price of the transaction
Example ¶
package main import ( "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockTransaction: 6, TransactionBytes: big.NewInt(7).Bytes(), } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } // Mocking transaction hash txHash := make([]byte, 32) _, err = rand.Read(txHash) if err != nil { return } tx, err := block.Transaction(txHash) if err != nil { return } gasPrice, err := tx.GasPrice() if err != nil { return } fmt.Println(gasPrice) }
Output: 7
func (*Transaction) GasTipCap ¶
func (t *Transaction) GasTipCap() (*big.Int, error)
GasTipCap returns the gasTipCap per gas of the transaction.
Example ¶
package main import ( "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockTransaction: 6, TransactionBytes: big.NewInt(7).Bytes(), } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } // Mocking transaction hash txHash := make([]byte, 32) _, err = rand.Read(txHash) if err != nil { return } tx, err := block.Transaction(txHash) if err != nil { return } gasTipCap, err := tx.GasTipCap() if err != nil { return } fmt.Println(gasTipCap) }
Output: 7
func (*Transaction) Hash ¶
func (t *Transaction) Hash() ([]byte, error)
Hash returns the transaction hash.
Example ¶
package main import ( "bytes" "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking transaction hash txHash := make([]byte, 32) _, err := rand.Read(txHash) if err != nil { return } // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockTransaction: 6, TransactionBytes: txHash, } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } tx, err := block.Transaction(txHash) if err != nil { return } hash, err := tx.Hash() if err != nil || bytes.Compare(hash, txHash) != 0 { return } fmt.Println("success") }
Output: success
func (*Transaction) Nonce ¶
func (t *Transaction) Nonce() (uint64, error)
Nonce returns the sender account nonce of the transaction.
Example ¶
package main import ( "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockTransaction: 6, TransactionU64: 7, } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } // Mocking transaction hash txHash := make([]byte, 32) _, err = rand.Read(txHash) if err != nil { return } tx, err := block.Transaction(txHash) if err != nil { return } nonce, err := tx.Nonce() if err != nil { return } fmt.Println(nonce) }
Output: 7
func (*Transaction) RawSignatures ¶
func (t *Transaction) RawSignatures() (rawSignatures, error)
RawSignatureValues returns the V, R, S signature values of the transaction. The return values should not be modified by the caller.
Example ¶
package main import ( "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockTransaction: 6, VSig: big.NewInt(7), RSig: big.NewInt(8), SSig: big.NewInt(9), } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } // Mocking transaction hash txHash := make([]byte, 32) _, err = rand.Read(txHash) if err != nil { return } tx, err := block.Transaction(txHash) if err != nil { return } rawSignatures, err := tx.RawSignatures() if err != nil { return } fmt.Println(rawSignatures.VSig, rawSignatures.RSig, rawSignatures.SSig) }
Output: 7 8 9
func (*Transaction) Send ¶
func (t *Transaction) Send() (err error)
SendTransaction injects a signed transaction into the pending pool for execution.
Example ¶
package main import ( "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockTransaction: 6, } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } // Mocking transaction hash txHash := make([]byte, 32) _, err = rand.Read(txHash) if err != nil { return } tx, err := block.Transaction(txHash) if err != nil { return } err = tx.Send() if err != nil { return } fmt.Println("success") }
Output: success
func (*Transaction) ToAddress ¶
func (t *Transaction) ToAddress() ([]byte, error)
ToAddress returns the recipient address of the transaction.
func (*Transaction) Value ¶
func (t *Transaction) Value() (*big.Int, error)
Value returns the ether amount of the transaction.
Example ¶
package main import ( "fmt" "math/big" "math/rand" ethereumSym "bitbucket.org/taubyte/go-sdk-symbols/ethereum/client" ethereum "bitbucket.org/taubyte/go-sdk/ethereum/client" ) func main() { // Mocking the calls to the vm for usage in tests and playground mockData := ethereumSym.MockData{ Client: 4, BlockByNumber: 5, BlockTransaction: 6, TransactionBytes: big.NewInt(7).Bytes(), } mockData.Mock() client, err := ethereum.New("https://testRPC.url") if err != nil { return } block, err := client.BlockByNumber(big.NewInt(20)) if err != nil { return } // Mocking transaction hash txHash := make([]byte, 32) _, err = rand.Read(txHash) if err != nil { return } tx, err := block.Transaction(txHash) if err != nil { return } value, err := tx.Value() if err != nil { return } fmt.Println(value) }
Output: 7