当提交智能合约部署后,会返回智能合约的地址。智能合约地址的生成逻辑在eth.api.go的submitTransaction函数中:
func submitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (common.Hash, error) {if err := b.SendTx(ctx, tx); err != nil { //提交交易return common.Hash{}, err}if tx.To() == nil { //交易成功后,交易的目标地址是空的话,说明是智能合约部署signer := types.MakeSigner(b.ChainConfig(), b.CurrentBlock().Number())from, err := types.Sender(signer, tx) //获取交易的发送地址if err != nil {return common.Hash{}, err}addr := crypto.CreateAddress(from, tx.Nonce()) //利用发送地址和nonce生成新的地址log.Info("Submitted contract creation", "fullhash", tx.Hash().Hex(), "contract", addr.Hex())} else {log.Info("Submitted transaction", "fullhash", tx.Hash().Hex(), "recipient", tx.To())}return tx.Hash(), nil