Hey guys thanks in advance!

Here is the interface provided by the go-ethereum library in the bin package. I need an example on how to implement this interface please :)

// ContractTransactor defines the methods needed to allow operating with contract
// on a write only basis. Beside the transacting method, the remainder are helpers
// used when the user does not provide some needed values, but rather leaves it up
// to the transactor to decide.
type ContractTransactor interface {
    // PendingCodeAt returns the code of the given account in the pending state.
    PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
    // PendingNonceAt retrieves the current pending nonce associated with an account.
    PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
    // SuggestGasPrice retrieves the currently suggested gas price to allow a timely
    // execution of a transaction.
    SuggestGasPrice(ctx context.Context) (*big.Int, error)
    // EstimateGas tries to estimate the gas needed to execute a specific
    // transaction based on the current pending state of the backend blockchain.
    // There is no guarantee that this is the true gas limit requirement as other
    // transactions may be added or removed by miners, but it should provide a basis
    // for setting a reasonable default.
    EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)
    // SendTransaction injects the transaction into the pending pool for execution.
    SendTransaction(ctx context.Context, tx *types.Transaction) error

I have some basic starter code here, so that people can see where I need the interface applied.

package main

import (

func main() {
    if err != nil {

    if err != nil {

    userMainAddress := userAddress.Address()
    mainConctractAddress := contractAddress.Address()
    if err != nil {
    //LOOOOOOOK HERE PEOPLE THANK YOU --------------------------------------

    var one bind.ContractTransactor
    transactor, err:=contracts.NewERC721Transactor(mainConctractAddress,one)
    if err != nil {
    auth, err := bind.NewTransactor(strings.NewReader(constants.GetEthKey()),constants.GetEthParaphrase())
    trans, err:=transactor.Mint(auth,userMainAddress,big.NewInt(123))

    if err != nil {


The ethclient package implements the ContractTransactor interface, so you just have to instantiate the client:

client, err := ethclient.Dial("https://mainnet.infura.io")

and then you can pass it to your contract transactor method:

transactor, err:= contracts.NewERC721Transactor(mainContractAddress, client)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.