PlatONnetwork/PlatON-Go

how to pass chainId in base.go func transact. if not specify ,then send tx error : invalid sender

Closed this issue · 2 comments

`
func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, input []byte) (*types.Transaction, error) {
var err error

// Ensure a valid value field and resolve the account nonce
value := opts.Value
if value == nil {
	value = new(big.Int)
}
var nonce uint64
if opts.Nonce == nil {
	nonce, err = c.transactor.PendingNonceAt(ensureContext(opts.Context), opts.From)
	if err != nil {
		return nil, fmt.Errorf("failed to retrieve account nonce: %v", err)
	}
} else {
	nonce = opts.Nonce.Uint64()
}
// Figure out the gas allowance and gas price values
gasPrice := opts.GasPrice
if gasPrice == nil {
	gasPrice, err = c.transactor.SuggestGasPrice(ensureContext(opts.Context))
	if err != nil {
		return nil, fmt.Errorf("failed to suggest gas price: %v", err)
	}
}
gasLimit := opts.GasLimit
if gasLimit == 0 {
	// Gas estimation cannot succeed without code for method invocations
	if contract != nil {
		if code, err := c.transactor.PendingCodeAt(ensureContext(opts.Context), c.address); err != nil {
			return nil, err
		} else if len(code) == 0 {
			return nil, ErrNoCode
		}
	}
	// If the contract surely has code (or code is not needed), estimate the transaction
	msg := ethereum.CallMsg{From: opts.From, To: contract, GasPrice: gasPrice, Value: value, Data: input}
	gasLimit, err = c.transactor.EstimateGas(ensureContext(opts.Context), msg)
	if err != nil {
		return nil, fmt.Errorf("failed to estimate gas needed: %v", err)
	}
}
// Create the transaction, sign it and schedule it for execution
var rawTx *types.Transaction
if contract == nil {
	rawTx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, input)
} else {
	rawTx = types.NewTransaction(nonce, c.address, value, gasLimit, gasPrice, input)
}
if opts.Signer == nil {
	return nil, errors.New("no signer to authorize the transaction with")
}
signedTx, err := opts.Signer(types.NewEIP155Signer(new(big.Int)), opts.From, rawTx)
if err != nil {
	return nil, err
}
if err := c.transactor.SendTransaction(ensureContext(opts.Context), signedTx); err != nil {
	return nil, err
}
return signedTx, nil

}
`

you can use SignerFn to pass chainID

type SignerFn func(types.Signer, common.Address, *types.Transaction) (*types.Transaction, error)

Closed due to lack of feedback for a long time