Documentation
¶
Index ¶
- func AddressFromPubKey(pubKey []byte) bytes.Address
- func HexToECDSABytes(hexString string) ([]byte, error)
- func ParseSignature(signature string) ([]byte, error)
- func PublicKeyFromPrivate(privateKey []byte) ([]byte, error)
- func PublicKeyFromSignedMessage(message []byte, signature []byte) ([]byte, error)
- func SignMessage(message, privKey []byte) ([]byte, error)
- func ToEthJsMessage(message string) []byte
- func VerifySignature(message, publicKey, signature []byte) error
- 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 []byte) (*Contract, *Transaction, error)
- func (c Client) NewBoundContract(abi io.Reader, address string) (*Contract, error)
- type Contract
- type ContractMethod
- func (c *ContractMethod) Call(inputParameters ...interface{}) ([]interface{}, error)
- func (c *ContractMethod) CallJSON(json []byte) ([]interface{}, error)
- func (c *ContractMethod) Name() string
- func (c *ContractMethod) Transact(chainID *big.Int, privateKey []byte, inputParameters ...interface{}) (*Transaction, error)
- func (c *ContractMethod) TransactJSON(chainID *big.Int, privateKey []byte, json []byte) (*Transaction, error)
- type Event
- 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.Number
- Block.Transaction
- Block.Transactions
- Client.BlockByNumber
- Client.CurrentBlockNumber
- Client.CurrentChainID
- Client.DeployContract
- Client.NewBoundContract
- Contract.Method
- Contract.Methods
- ContractMethod.Call
- ContractMethod.Transact
- HexToECDSABytes
- New
- SignMessage
- 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 ¶
func AddressFromPubKey ¶ added in v0.2.7
AddressFromPubKey returns the Address for the given public key.
func HexToECDSABytes ¶ added in v0.2.5
HexToECDSABytes returns the ECDSA []byte format of the given hex string representation of a Private Key.
Example ¶
package main
import (
"fmt"
ethereum "github.com/taubyte/go-sdk/ethereum/client"
)
var privateKey []byte
var err error
func main() {
privateKey, err = ethereum.HexToECDSABytes("91e4a13e5a30ad353cdf5ea7bb909dfdf967122e3b43e331ad947b68a3899b2c")
if err != nil {
return
}
fmt.Println("success")
}
Output: success
func ParseSignature ¶ added in v0.2.7
ParseSignature parses a hex string signature to bytes
func PublicKeyFromPrivate ¶ added in v0.2.5
PublicKeyFromPrivate returns the uncompressed ECDSA public key from the given privateKey,
func PublicKeyFromSignedMessage ¶ added in v0.2.5
PublicKeyFromSignedMessage returns the ECDSA public key used to sign the given message to the given signature.
func SignMessage ¶
SignMessage returns an ECDSA signed message
Example ¶
privateKey, err = ethereum.HexToECDSABytes("91e4a13e5a30ad353cdf5ea7bb909dfdf967122e3b43e331ad947b68a3899b2c")
if err != nil {
return
}
publicKey, err = ethereum.PublicKeyFromPrivate(privateKey)
if err != nil {
return
}
signature, err := ethereum.SignMessage([]byte("hello world"), privateKey)
if err != nil {
return
}
err = ethereum.VerifySignature([]byte("hello world"), publicKey, signature)
if err != nil {
return
}
fmt.Println("success")
Output: success
func ToEthJsMessage ¶ added in v0.2.7
ToEthJsMessage returns the signed message in the JS Ethereum message format as bytes.
func VerifySignature ¶
VerifySignature checks the signed ECDSA message with the original message to verify if the message was signed by the given public key
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
Block defines wrappers for a block retrieved by the client.
func (*Block) Number ¶
Number returns the *big.Int value of the block number
Example ¶
package main
import (
"fmt"
"math/big"
ethereumSym "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 ¶
func New(url string, ops ...rpc.ClientOption) (Client, error)
New connects a client to the given rpc URL.
Example ¶
package main
import (
"fmt"
ethereumSym "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 ¶ added in v0.3.1
CurrentChainID retrieves the current chain ID for transaction replay protection.
Example ¶
package main
import (
"fmt"
"math/big"
ethereumSym "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 ¶
func (c Client) DeployContract(abi, byteCode io.Reader, chainID *big.Int, privateKey []byte) (*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, []byte("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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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
}
ContractMethod defines the contract method and wraps the methods for the contract method.
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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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) CallJSON ¶ added in v0.3.8
func (c *ContractMethod) CallJSON(json []byte) ([]interface{}, error)
func (*ContractMethod) Name ¶
func (c *ContractMethod) Name() string
Name returns the name of the method.
func (*ContractMethod) Transact ¶
func (c *ContractMethod) Transact(chainID *big.Int, privateKey []byte, 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, []byte("private_key"), big.NewInt(5))
if err != nil {
return
}
fmt.Println("success")
Output: success
func (*ContractMethod) TransactJSON ¶ added in v0.3.8
func (c *ContractMethod) TransactJSON(chainID *big.Int, privateKey []byte, json []byte) (*Transaction, error)
type Event ¶ added in v0.3.8
type Event struct {
// contains filtered or unexported fields
}
Event defines the Ethereum event and wraps the methods for the event.
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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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.Equal(hash, txHash) {
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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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)
RawSignatures 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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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)
Send injects a signed transaction into the pending pool for execution.
Example ¶
package main
import (
"fmt"
"math/big"
"math/rand"
ethereumSym "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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 "github.com/taubyte/go-sdk-symbols/ethereum/client"
ethereum "github.com/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